29 04, 2009

include

By | 2009-04-27T10:08:20+00:00 April 29th, 2009|Categories: PHP, Ruby|Tags: , |Comments Off on include

The include() statement includes and evaluates a specified file. The difference between include() and require() is that require() results in a Fatal Error upon failure, whereas include() does not, it only produces a Warning.

include() is not a function in PHP, it is a language construct.

PHP

include('../config.php');

Ruby

include('../config.rb');
26 04, 2009

require

By | 2009-04-24T13:52:18+00:00 April 26th, 2009|Categories: PHP, Ruby|Tags: , |Comments Off on require

The require() statement includes and evaluates a specified file. The difference between require() and include() is that require() results in a Fatal Error upon failure, whereas include() does not, it only produces a Warning.

require() is not a function in PHP, it is a language construct.

PHP

require ('../config.php');

Ruby

require ('../config.rb');
23 04, 2009

printf

By | 2009-04-24T13:35:51+00:00 April 23rd, 2009|Categories: PHP, Ruby|Tags: , , , |1 Comment

Output a formatted string.

PHP

$format = 'There are %d monkeys in the %s';
printf($format, 5, 'tree');
// => There are 5 monkeys in the tree

Ruby

my_string = 'There are %d monkeys in the %s';
printf(my_string, 5, 'tree');
# => There are 5 monkeys in the tree
20 04, 2009

print

By | 2009-04-24T13:18:06+00:00 April 20th, 2009|Categories: PHP, Ruby|Tags: , , |Comments Off on print

Output a string.

Strictly speaking, print() is not a function in PHP, it is a language construct (similar to echo() ).

PHP

print 'Hello World!';
// => Hello World!

Ruby

print 'Hello World!'
# => Hello World!
17 04, 2009

echo

By | 2009-04-24T13:13:16+00:00 April 17th, 2009|Categories: PHP, Ruby|Tags: , , |2 Comments

Output one or more strings.

Strictly speaking, echo() is not a function in PHP, it is a language construct.

PHP

echo 'Hello World!';
// => Hello World!

Ruby

print 'Hello World!'
# => Hello World!
14 04, 2009

sort

By | 2009-04-23T15:05:50+00:00 April 14th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on sort

Sorts an array with elements arranged from lowest to highest.

PHP

$a = array('a', 'b', 'e', 'g', 'c', 'd');
sort($a);
print_r($a);
/*
Array (
	[0] => a
	[1] => b
	[2] => c
	[3] => d
	[4] => e
	[5] => g
)
*/

Ruby

a = [ "d", "a", "e", "c", "b" ];
puts a.sort;
# => ["a", "b", "c", "d", "e"]
11 04, 2009

count

By | 2009-04-11T15:17:35+00:00 April 11th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on count

Returns the number of elements in an array.

PHP

$a = array('first' => 1, 'second' => 2);
echo count($a);
// => 2

Ruby

my_array = [1, 2];
puts my_array.length;
# => 2
8 04, 2009

array_key_exists

By | 2009-10-15T22:42:32+00:00 April 8th, 2009|Categories: PHP, Ruby|Tags: , |Comments Off on array_key_exists

Returns TRUE if the given argument is set in the array. The argument passed in can be any value possible for an array index.

PHP

$a = array('first' => 1, 'second' => 2);
var_dump( array_key_exists('first', $a) );
// => true

Ruby

animals = {:sheep => 1, :cow => 2};
puts animals.include?(:cow);
# => true
5 04, 2009

array_sum

By | 2009-10-15T22:42:43+00:00 April 5th, 2009|Categories: PHP, Ruby|Tags: , , , |2 Comments

Returns the sum of values in an array.

PHP

$a = array(2, 4, 6, 8);
echo array_sum($a);
// => 20

Ruby

a_var = [2, 4, 6, 8];
puts a_var.inject {|sum,x| sum ? sum + x : x };
# => 20

In the code above, the return value from the ruby code will be nil if the array used is empty. This is not exactly the same behaviour as PHP, since the array_sum() function will always return a number. We can force ruby to always return a float (or an int) too, even if the array is empty, by adding a bit of type casting to the final result:

Ruby

a_var = [];
puts a_var.inject {|sum,x| sum ? sum + x : x }.to_f;
# => 0.0
2 04, 2009

pi

By | 2009-04-01T16:04:36+00:00 April 2nd, 2009|Categories: PHP, Ruby|Tags: , , |Comments Off on pi

Returns the value of PI to 14 (default) decimal places. This precision can be altered in the php.ini file.

PHP

echo pi();
// => 3.1415926535898

Ruby

puts Math::PI;
# => 3.14159265358979

In the code above, PI is actually a constant of the Module Math. PHP also has a constant which stores the approximate value of PI – M_PI.

PHP

echo M_PI();
// => 3.1415926535898

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.