24 02, 2010

array_keys

By | 2010-02-24T12:31:01+00:00 February 24th, 2010|Categories: PHP, Ruby|Tags: , , |Comments Off on array_keys

The array_keys() function in PHP takes an array as it’s argument and returns all the keys in that array (as a numeric array).

PHP

$array = array('go' => 'green', 'stop' => 'red');
var_dump( array_keys($array) );
/*
Array (
	[0] => go
	[1] => stop
)
*/

To replicate this functionality in Ruby, we need to use a Hash object, since arrays in Ruby don’t use associative key/value pairs.

Ruby

array = { :go => 'green', :stop => 'red' };
puts array.keys;
# => [:go, :stop]
17 02, 2010

array_product

By | 2010-02-17T11:38:14+00:00 February 17th, 2010|Categories: PHP, Ruby|Tags: , , |Comments Off on array_product

The array_product() PHP function returns the product of all values in an array. In other words, it multiplies all values in the array together, and returns the result as a number.

PHP

$a = array('1', '2', '3');
$product_total = array_product($a);
echo $product_total;
// => 6 

Ruby

a = [ "1", "2", "3" ];
product_total = a.inject {|product, element| product * element }
puts product_total;
# => 6 
16 02, 2010

array_rand

By | 2010-02-16T15:18:42+00:00 February 16th, 2010|Categories: PHP, Ruby|Tags: , , , , , |1 Comment

The array_rand() function in PHP randomly selects one or more elements from an array.

PHP

$users = array('john', 'jane', 'tim', 'alex');
$lucky_winner = array_rand($users);
echo $lucky_winner;
// alex 

Ruby

users = [ 'john', 'jane', 'tim', 'alex' ];
lucky_winner = users[rand(users.length)];
puts lucky_winner;
# => alex 

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.