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.
20 09, 2009

PHP Array

By | 2009-09-25T13:53:43+00:00 September 20th, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on PHP Array

A PHP array can be thought of as a variable which can store multiple other variables. Every item in a PHP array is known as an element and is composed of a key and a value. There are 2 main types of PHP arrays:

  1. Numeric Array
  2. Associative Array

Each of these can in turn be a Multidimensional Array.

Example Numeric Array:

$terms = array('array', 'element', 'key', 'value');
var_dump($terms);
/* => Array
(
    [0] => array
    [1] => element
    [2] => key
    [3] => value
)
*/

Example Associative Array:

$terms = array(
	'term1' => 'array', 
	'term2' => 'element', 
	'term3' => 'key', 
	'term4' => 'value'
);
var_dump($terms);
/* => Array
(
    [term1] => array
    [term2] => element
    [term3] => key
    [term4] => value
)
*/

Find out more information about PHP’s Numeric Array, Associative Array or Multidimensional Array.

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"]