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.
19 10, 2010

array_merge

By | 2010-10-19T11:01:55+00:00 October 19th, 2010|Categories: PHP, Ruby|Tags: , , , , |1 Comment

The array_merge() function in PHP merges 2 arrays by appending the second array onto the first array, and returning the resulting array.

The way to do this in Ruby depends on the type of data – if dealing with associative arrays (known as a hash in Ruby), we can use the merge() method of the Ruby Hash class.

PHP

$user_details = array('name' => 'John', 'age' => 20);
$account_details = array('credits' => '50', 'id' => 4);

$user = array_merge($user_details, $account_details);

print_r($user);
/*
Array (
    [name] => John
    [age] => 20
    [credits] => 50
    [id] => 4
)
*/

Ruby

user_details = { :name => 'John', :age => 20 }
account_details = { :credits => 50, :id => 4 }

p user_details.merge(account_details);
# => {:credits=>50, :name=>"John", :id=>4, :age=>20}

Merging numeric arrays in Ruby is much easier as shown below (PHP example given first).

PHP

$start = array(1, 2, 3);
$finish = array(4, 5, 6);

$nums = array_merge($start, $finish);

print_r($nums);
/*
Array (
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)
*/

Ruby

start  = [1, 2, 3];
finish = [4, 5, 6];

nums = start + finish;

p nums;
# => [1, 2, 3, 4, 5, 6]