Class used for manipulation of arrays.
_flatten( array $results , string $key null )
Flattens an array for sorting
$results
$key
optional null array
_map( array $array , string $class , boolean $primary false )
Maps the given value as an object. If $value is an object, it returns $value. Otherwise it maps $value as an object of type $class, and if primary assign _name_ $key on first array. If $value is not empty, it will be used to set properties of returned object (recursively). If $key is numeric will maintain array structure
$array
$class
$primary
optional false mixed
apply( mixed $path , array $data , mixed $callback , array $options array() )
Allows the application of a callback method to elements of an array extracted by a Set::extract() compatible path.
$path
$data
$callback
$options
optional array() mixed
check( string|array $data , string|array $path null )
Checks if a particular path is set in an array
$data
$path
optional null boolean
classicExtract( array $data , string|array $path null )
Gets a value from an array or object that is contained in a given path using an array path syntax, i.e.: "{n}.Person.{[a-z]+}" - Where "{n}" represents a numeric key, "Person" represents a string literal, and "{[a-z]+}" (i.e. any string literal enclosed in brackets besides {n} and {s}) is interpreted as a regular expression.
$data
$path
optional null mixed
combine( array|object $data , string|array $path1 null , string|array $path2 null , string $groupPath null )
Creates an associative array using a $path1 as the path to build its keys, and optionally $path2 as path to get the values. If $path2 is not specified, all values will be initialized to null (useful for Set::merge). You can optionally group the values by what is obtained when following the path specified in $groupPath.
$data
$path1
optional null $path2
optional null $groupPath
optional null array
contains( array $val1 , array $val2 null )
Determines if one Set or array contains the exact keys and values of another.
$val1
$val2
optional null boolean
countDim( array $array , boolean $all false , integer $count 0 )
Counts the dimensions of an array. If $all is set to false (which is the default) it will only consider the dimension of the first element in the array.
$array
$all
optional false $count
optional 0 integer
diff( mixed $val1 , mixed $val2 null )
Computes the difference between a Set and an array, two Sets, or two arrays
$val1
$val2
optional null array
enum( string $select , array|string $list null )
Return a value from an array list if the key exists.
If a comma separated $list is passed arrays are numeric with the key of the first being 0 $list = 'no, yes' would translate to $list = array(0 => 'no', 1 => 'yes');
If an array is used, keys can be strings example: array('no' => 0, 'yes' => 1);
$list defaults to 0 = no 1 = yes if param is not passed
$select
$list
optional null string
expand( array $data , string $separator '.' )
Expand/unflattens a string to an array
For example, unflattens an array that was collapsed with Set::flatten()
into a multi-dimensional array. So, array('0.Foo.Bar' => 'Far')
becomes array(array('Foo' => array('Bar' => 'Far')))
.
$data
$separator
optional '.' array
extract( string $path , array $data null , array $options array() )
Implements partial support for XPath 2.0. If $path does not contain a '/' the call is delegated to Set::classicExtract(). Also the $path and $data arguments are reversible.
Warning: Even so it has plenty of unit tests the XPath support has not gone through a lot of real-world testing. Please report Bugs as you find them. Suggestions for additional features to implement are also very welcome!
$path
$data
optional null $options
optional array() mixed
filter( array $var )
Filters empty elements out of a route array, excluding '0'.
$var
mixed
flatten( array $data , string $separator '.' )
Collapses a multi-dimensional array into a single dimension, using a delimited array path for each array element's key, i.e. array(array('Foo' => array('Bar' => 'Far'))) becomes array('0.Foo.Bar' => 'Far').
$data
$separator
optional '.' array
format( array $data , string $format , array $keys )
Returns a series of values extracted from an array, formatted in a format string.
$data
$format
$keys
array|null
get( array $input , string|array $path null )
Return the value at the specified position
$input
$path
optional null the
insert( array $list , string $path , array $data null )
Inserts $data into an array as defined by $path.
$list
$path
$data
optional null array
map( string $class 'stdClass' , string $tmp 'stdClass' )
Maps the contents of the Set object to an object hierarchy. Maintains numeric keys as arrays of objects
$class
optional 'stdClass' $tmp
optional 'stdClass' object|null
matches( string|array $conditions , array $data array() , integer $i null , integer $length null )
This function can be used to see if a single item or a given xpath match certain conditions.
$conditions
$data
optional array() $i
optional null $length
optional null boolean
merge( array $data , array $merge null )
This function can be thought of as a hybrid between PHP's array_merge and array_merge_recursive. The difference to the two is that if an array key contains another array then the function behaves recursive (unlike array_merge) but does not do if for keys containing strings (unlike array_merge_recursive).
Since this method emulates array_merge
, it will re-order numeric keys. When combined with out of order numeric keys containing arrays, results can be lossy.
Note: This function will work with an unlimited amount of arguments and typecasts non-array parameters into arrays.
$data
$merge
optional null array
nest( mixed $data , array $options array() )
Takes in a flat array and returns a nested array
$data
$options
optional array() array
normalize( mixed $list , boolean $assoc true , string $sep ',' , boolean $trim true )
Normalizes a string or array list.
$list
$assoc
optional true $sep
optional ',' $trim
optional true array
numeric( array $array null )
Checks to see if all the values in the array are numeric
$array
optional null boolean
pushDiff( array $array , array $array2 )
Pushes the differences in $array2 onto the end of $array
$array
$array2
array
remove( array $list , string $path null )
Removes an element from a Set or array as defined by $path.
$list
$path
optional null array
reverse( object $object )
Converts an object into an array.
$object
array
sort( array $data , string $path , string $dir )
Sorts an array by any value, determined by a Set-compatible path
$data
$path
$dir
array
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-Set.html