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.
4 10, 2009

array_values

By | 2009-10-15T22:35:54+00:00 October 4th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on array_values

The array_values() function in PHP takes an array and returns all it’s values as a numeric array.

PHP

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

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.values;
# => ["green", "red"]
1 10, 2009

list

By | 2009-10-15T22:36:18+00:00 October 1st, 2009|Categories: PHP, Ruby|Tags: , , , , , , |Comments Off on list

The list() function in PHP is used to assign multiple variables as if they were an array. Technically, list() is not a function in PHP, it is a language construct.

Ruby has no real need for a function such as list(), as the same can be achieve using parallel assignment – i.e. assigning comma separated variables to elements of an array using the normal assignment operator.

PHP

$langs = array('php', 'ruby', 'perl');
list($lang1, $lang2, $lang3) = $langs;
echo $lang1;	// php
echo $lang2;	// ruby
echo $lang3;	// perl

Ruby

langs = [ "php", "ruby", "perl" ];
lang1, lang2, lang3 = langs;
puts lang1;	# php
puts lang2;	# ruby
puts lang3;	# perl
23 07, 2009

array_combine

By | 2009-10-15T22:41:01+00:00 July 23rd, 2009|Categories: PHP, Ruby|Tags: , , , , , |3 Comments

The array_combine() function creates an associative array (hash) by using one array for keys and another for values.

PHP

$a = array('python', 'lisp', 'perl');
$b = array('PY', 'LI', 'PE');
$c = array_combine($a, $b);

print_r($c);
=> /* 
Array
(
    [python] => PY
    [lisp] => LI
    [perl] => PE
)
*/

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

Since there is no exact equivalent of to the array_combine() function in Ruby, we manually create a hash from two different arrays.

Ruby

p1 = ['python', 'lisp', 'perl'];
p2 = ['PY', 'LI', 'PE'];

# initialize the hash
combined_hash = {}

# build the hash from 2 different arrays
p2.each_with_index do |val, key| 
  combined_hash[p1[key]] = val
end

# print resulting hash
p combined_hash
=> # ["python"=>"PY", "lisp"=>"LI", "perl"=>"PE"]
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
28 03, 2009

array_change_key_case

By | 2009-10-15T22:42:53+00:00 March 28th, 2009|Categories: PHP, Ruby|Tags: , , , , |1 Comment

This function changes all keys in an array by returning an array with all keys from argument lowercased or uppercased. Numbered indices are left as is.

PHP

$input_array = array('FirSt' => 1, 'SecOnd' => 4);
print_r( array_change_key_case($input_array, CASE_UPPER) );
// => array('FIRST' => 1, 'SECOND' => 4);

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

hash = {'FirSt' => 1, 'SecOnd' => 4}
 
result = hash.inject({}) do |hash, keys|
  hash[keys[0].upcase] = keys[1]
  hash
end
p result
# => { 'FIRST' => 1, 'SECOND' => 4 }