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.

17 09, 2009

crc32

By | 2009-09-25T13:52:34+00:00 September 17th, 2009|Categories: PHP, Ruby|Tags: , |1 Comment

The crc32() function in PHP generates the cyclic redundancy checksum (CRC) polynomial of 32-bit lengths of a string, and returns it as an integer.

PHP

$checksum = crc32('hello world');
echo $checksum;
// => 222957957

Ruby

require 'zlib';
puts Zlib.crc32('hello world');
# => 222957957
14 09, 2009

reset

By | 2009-10-15T22:36:48+00:00 September 14th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on reset

The reset() function in PHP sets the internal pointer of an array to its first element. However in Ruby, there is no internal array pointer – as such Ruby doesn’t have an equivalent to PHP’s reset() function.

11 09, 2009

pos

By | 2009-09-21T13:31:16+00:00 September 11th, 2009|Categories: PHP, Ruby|Tags: , , , , |Comments Off on pos

The pos() function is only an alias of current, which returns the key and value of the element the current array pointer is pointing to. However since Ruby doesn’t have an internal array pointer, this function does not have a Ruby equivalent.

For further information about pos(), see current().

8 09, 2009

current

By | 2009-10-15T22:38:27+00:00 September 8th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on current

The current() function in PHP returns the key and value of the element the current array pointer is pointing to. However in Ruby, there is no internal array pointer – as such Ruby doesn’t have an equivalent to PHP’s current() function.

5 09, 2009

key

By | 2009-10-15T22:38:46+00:00 September 5th, 2009|Categories: PHP, Ruby|Tags: , , , |Comments Off on key

The key() function in PHP returns the index element of the element the current array pointer is pointing to. However in Ruby, there is no internal array pointer – as such Ruby doesn’t have an equivalent to PHP’s key() function.

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.