Class used for manipulation of arrays.
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
Allows the application of a callback method to elements of an array extracted by a Set::extract() compatible path.
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.
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.
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.
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.
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').
Maps the contents of the Set object to an object hierarchy. Maintains numeric keys as arrays of objects
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).
_flatten( array $results , string $key null )
Flattens an array for sorting
$results
$key
optional null _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 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
Callback method to be applied to extracted data. See http://ca2.php.net/manual/en/language.pseudo-types.php#language.types.callback for examples of callback formats.
$options
optional array() Options are: - type : can be pass, map, or reduce. Map will handoff the given callback to array_map, reduce will handoff to array_reduce, and pass will use call_user_func_array().
check( string|array $data , string|array $path null )
Checks if a particular path is set in an array
$data
$path
optional null 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 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 contains( array $val1 , array $val2 null )
Determines if one Set or array contains the exact keys and values of another.
$val1
$val2
optional null 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 diff( mixed $val1 , mixed $val2 null )
Computes the difference between a Set and an array, two Sets, or two arrays
$val1
$val2
optional null Returns the key => value pairs that are not common in $val1 and $val2 The expression for this function is($val1 - $val2) + ($val2 - ($val1 - $val2))
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 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 '.' 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() filter( array $var )
Filters empty elements out of a route array, excluding '0'.
$var
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 '.' format( array $data , string $format , array $keys )
Returns a series of values extracted from an array, formatted in a format string.
$data
$format
$keys
get( array $input , string|array $path null )
Return the value at the specified position
$input
$path
optional null insert( array $list , string $path , array $data null )
Inserts $data into an array as defined by $path.
$list
$path
$data
optional null 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' 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 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 nest( mixed $data , array $options array() )
Takes in a flat array and returns a nested array
$data
$options
optional array() Options are: children - the key name to use in the resultset for children idPath - the path to a key that identifies each entry parentPath - the path to a key that identifies the parent of each entry root - the id of the desired top-most result
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 numeric( array $array null )
Checks to see if all the values in the array are numeric
$array
optional null pushDiff( array $array , array $array2 )
Pushes the differences in $array2 onto the end of $array
$array
$array2
remove( array $list , string $path null )
Removes an element from a Set or array as defined by $path.
$list
$path
optional null reverse( object $object )
Converts an object into an array.
$object
sort( array $data , string $path , string $dir )
Sorts an array by any value, determined by a Set-compatible path
$data
$path
$dir
© 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.
https://api.cakephp.org/2.9/class-Set.html