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.
17 07, 2009

array_pop

By | 2009-10-15T22:41:20+00:00 July 17th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on array_pop

The array_pop() function removes the element off the end of an array and returns it’s value.

PHP

$my_array = array('java', 'ruby', 'python', 'php');
echo array_pop($my_array);
=> // php

Ruby

my_array = ['java', 'ruby', 'python', 'php'];
puts my_array.pop
=> # php
1 06, 2009

implode

By | 2009-10-15T22:42:21+00:00 June 1st, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on implode

The implode function takes and array and forms a string by concatenating the elements in the array.

PHP

$langs = array('python', 'java', 'ruby');
$string = implode(', ', $langs);
echo $string;
// => python, java, ruby

Ruby

puts ['perl', 'python', 'java'].join(', ');
# => python, java, ruby
29 05, 2009

explode

By | 2009-10-15T22:42:12+00:00 May 29th, 2009|Categories: PHP, Ruby|Tags: , , , , , |Comments Off on explode

The explode function takes 2 parameters – the first is the delimiter, and the second is the string to be exploded. It returns an array of strings, each of which is a substring of the original, formed by splitting the original string on boundaries formed by the string delimiter.

PHP

$my_string = 'perl, python, java';
$array = explode(', ', $my_string);
var_dump($a);
/*
Array (
	[0] => perl
	[1] => python
	[2] => java
)
*/

Ruby

my_string = 'perl, python, java';
puts my_string.split(', ');
# => ["perl", "python", "java"]
26 05, 2009

shuffle

By | 2009-05-21T16:29:35+00:00 May 26th, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on shuffle

Randomizes the order of the elements in an array.

PHP

$a = array('a', 'b', 'c', 'd');
shuffle($a);
print_r($a);
/*
Array (
	[0] => d
	[1] => b
	[2] => c
	[3] => a
)
*/

Ruby

a = [ "a", "b", "c", "d" ];
puts a.sort_by{ rand };
# => ["d", "b", "c", "a"]
14 04, 2009

sort

By | 2009-04-23T15:05:50+00:00 April 14th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on sort

Sorts an array with elements arranged from lowest to highest.

PHP

$a = array('a', 'b', 'e', 'g', 'c', 'd');
sort($a);
print_r($a);
/*
Array (
	[0] => a
	[1] => b
	[2] => c
	[3] => d
	[4] => e
	[5] => g
)
*/

Ruby

a = [ "d", "a", "e", "c", "b" ];
puts a.sort;
# => ["a", "b", "c", "d", "e"]
11 04, 2009

count

By | 2009-04-11T15:17:35+00:00 April 11th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on count

Returns the number of elements in an array.

PHP

$a = array('first' => 1, 'second' => 2);
echo count($a);
// => 2

Ruby

my_array = [1, 2];
puts my_array.length;
# => 2
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
5 04, 2009

array_sum

By | 2009-10-15T22:42:43+00:00 April 5th, 2009|Categories: PHP, Ruby|Tags: , , , |2 Comments

Returns the sum of values in an array.

PHP

$a = array(2, 4, 6, 8);
echo array_sum($a);
// => 20

Ruby

a_var = [2, 4, 6, 8];
puts a_var.inject {|sum,x| sum ? sum + x : x };
# => 20

In the code above, the return value from the ruby code will be nil if the array used is empty. This is not exactly the same behaviour as PHP, since the array_sum() function will always return a number. We can force ruby to always return a float (or an int) too, even if the array is empty, by adding a bit of type casting to the final result:

Ruby

a_var = [];
puts a_var.inject {|sum,x| sum ? sum + x : x }.to_f;
# => 0.0
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 }