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

array_shift

By | 2009-10-27T15:39:23+00:00 October 14th, 2009|Categories: PHP, Ruby|Tags: , , |Comments Off on array_shift

The array_shift() function in PHP removes an element from the beginning of an array and returns it.

PHP

$my_array = array('a', 'b', 'c', 'd');
$my_element = array_shift($my_array);
print_r($my_element);
/*
Array (
	[0] => a
)
*/

Ruby

my_array = [ "a", "b", "c", "d" ];
puts my_array.shift;
# => ["a"]
10 10, 2009

array_unique

By | 2009-10-19T08:55:30+00:00 October 10th, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on array_unique

The array_unique() function in PHP takes an array and filters our any duplicates values, returning the array with only unique values present.

PHP

$elements = array('php', 'ruby', 'perl', 'php');
array_unique($elements);
print_r($elements);
/*
Array (
	[0] => php
	[1] => ruby
	[2] => perl
)
*/

Ruby

elements = [ "php", "ruby", "perl", "php" ];
puts elements.uniq;
# => ["php", "ruby", "perl"]
7 10, 2009

array_unshift

By | 2009-10-16T08:08:17+00:00 October 7th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on array_unshift

The array_unshift() function in PHP prepends elements onto the beginning of an array.

PHP

$cue = array('http', 'https', 'ftp');
array_unshift($cue, 'ssh');
print_r($cue);
/*
Array (
	[0] => ssh
	[1] => http
	[2] => https
	[3] => ftp
)
*/

Ruby has an identical Array method, named unshift:

Ruby

cue = [ "http", "https", "ftp" ];
cue.unshift('ssh');
puts cue;
# => [ "ssh", "http", "https", "ftp"]
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
28 09, 2009

in_array

By | 2009-10-14T13:03:32+00:00 September 28th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on in_array

The in_array() function in PHP checks if a value exists in an array – returning true if it does, or false otherwise.

The last argument in this function forces a strict type check of the value in PHP. Since Ruby does not consider a Fixnum of 1 and a String of ‘1’ to be the same – it always operates as if the last argument were set to true.

PHP

$my_array = array('a', 'b', 'c', 'd');
if('a', in_array($a), true) {
	echo 'Found it in the array';
}
// => Found it in the array

Ruby

my_array = [ "a", "b", "c", "d" ];
if( my_array.include?('a') ) {
	 puts 'Found it in the array';
}
# => Found it in the array
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.