array('Bar' => 'Far'))) becomes * array('0.Foo.Bar' => 'Far'). * * @param array $data Array to flatten * @param string $separator String used to separate array key elements in a path, defaults to '.' * @return array * @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::flatten */ public static function flatten(array $data, $separator = '.') { $result = array(); $stack = array(); $path = null; reset($data); while (!empty($data)) { $key = key($data); $element = $data[$key]; unset($data[$key]); if (is_array($element)) { if (!empty($data)) { $stack[] = array($data, $path); } $data = $element; $path .= $key . $separator; } else { $result[$path . $key] = $element; } if (empty($data) && !empty($stack)) { list($data, $path) = array_pop($stack); } } return $result; } public static function merge(array $data, $merge) { } /** * Counts the dimensions of an array. * Only considers the dimension of the first element in the array. * * If you have an un-even or hetrogenous array, consider using Set2::maxDimensions() * to get the dimensions of the array. * * @param array $array Array to count dimensions on * @return integer The number of dimensions in $data * @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::countDim */ public static function dimensions(array $data) { if (empty($data)) { return 0; } reset($data); $depth = 1; while ($elem = array_shift($data)) { if (is_array($elem)) { $depth += 1; $data =& $elem; } else { break; } } return $depth; } /** * Counts the dimensions of *all* array elements. Useful for finding the maximum * number of dimensions in a mixed array. * * @param array $data Array to count dimensions on * @return integer The maximum number of dimensions in $data * @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::countDim */ public static function maxDimensions(array $data) { $depth = array(); if (is_array($data) && reset($data) !== false) { foreach ($data as $value) { $depth[] = Set2::dimensions((array)$value) + 1; } } return max($depth); } /** * Map a callback across all elements in a set. * Can be provided a path to only modify slices of the set. * */ public static function map(array $data, $path, $function = null) { } public static function sort(array $data, $path, $dir) { } public static function diff(array $data, $data2) { } public static function normalize(array $data, $assoc = true) { } }