CArray
Package | Core |
---|---|
Inheritance | class CArray |
$Id: arr.php 3769 2008-12-15 00:48:56Z zombor $
Public Methods
Method | Description | Defined By |
---|---|---|
binary_search() | Binary search algorithm. | CArray |
callback_string() | Return a callback array from a string, eg: limit[10,20] would become | CArray |
extract() | Extract one or more keys from an array. Each key given after the first | CArray |
map_recursive() | Because PHP does not have this function, and array_walk_recursive creates | CArray |
merge() | Emulates array_merge_recursive, but appends numeric keys and replaces | CArray |
overwrite() | Overwrites an array with values from input array(s). | CArray |
range() | Fill an array with a range of numbers. | CArray |
remove() | Removes a key from an array and returns the value. | CArray |
rotate() | Rotates a 2D array clockwise. | CArray |
to_object() | Recursively convert an array to an object. | CArray |
unshift_assoc() | Because PHP does not have this function. | CArray |
Method Details
public static integer binary_search(mixed $needle, array $haystack, boolean $nearest=false, mixed $sort=false)
| ||
$needle | mixed | the value to search for |
$haystack | array | an array of values to search in |
$nearest | boolean | return false, or the nearest value |
$sort | mixed | sort the array before searching it |
{return} | integer |
Binary search algorithm.
public static array callback_string(string $str)
| ||
$str | string | callback string |
{return} | array |
Return a callback array from a string, eg: limit[10,20] would become array('limit', array('10', '20'))
public static array extract(array $search, string $keys)
| ||
$search | array | array to search |
$keys | string | key name |
{return} | array |
Extract one or more keys from an array. Each key given after the first argument (the array) will be extracted. Keys that do not exist in the search array will be NULL in the extracted data.
public static array map_recursive(mixed $callback, array $array)
| ||
$callback | mixed | callback to apply to each member of the array |
$array | array | array to map to |
{return} | array |
Because PHP does not have this function, and array_walk_recursive creates references in arrays and is not truly recursive.
public static array merge()
| ||
{return} | array |
Emulates array_merge_recursive, but appends numeric keys and replaces associative keys, instead of appending all keys.
public static array overwrite(array $array1)
| ||
$array1 | array | key array |
{return} | array |
Overwrites an array with values from input array(s). Non-existing keys will not be appended!
public static array range(integer $step=10, integer $max=100)
| ||
$step | integer | stepping |
$max | integer | ending number |
{return} | array |
Fill an array with a range of numbers.
public static mixed remove(string $key, array $array)
| ||
$key | string | key to return |
$array | array | array to work on |
{return} | mixed | value of the requested array key |
Removes a key from an array and returns the value.
public static array rotate(array $source_array, boolean $keep_keys=true)
| ||
$source_array | array | array to rotate |
$keep_keys | boolean | keep the keys in the final rotated array. the sub arrays of the source array need to have the same key values. if your subkeys might not match, you need to pass FALSE here! |
{return} | array |
Rotates a 2D array clockwise. Example, turns a 2x3 array into a 3x2 array.
public static object to_object(array $array, $class='stdClass')
| ||
$array | array | array to convert |
$class | ||
{return} | object |
Recursively convert an array to an object.
public static array unshift_assoc(array $array, string $key, mixed $val)
| ||
$array | array | array to unshift |
$key | string | key to unshift |
$val | mixed | value to unshift |
{return} | array |
Because PHP does not have this function.