Skip to content

Commit

Permalink
Update docs for Hash::apply()
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 17, 2012
1 parent f2d1eba commit f326058
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Cake/Utility/Hash.php
Expand Up @@ -698,6 +698,17 @@ public static function reduce(array $data, $path, $function) {
* Apply a callback to a set of extracted values using `$function`.
* The function will get the extracted values as the first argument.
*
* ### Example
*
* You can easily count the results of an extract using apply().
* For example to count the comments on an Article:
*
* `$count = Hash::apply($data, 'Article.Comment.{n}', 'count');`
*
* You could also use a function like `array_sum` to sum the results.
*
* `$total = Hash::apply($data, '{n}.Item.price', 'array_sum');`
*
* @param array $data The data to reduce.
* @param string $path The path to extract from $data.
* @return mixed The results of the applied method.
Expand Down

0 comments on commit f326058

Please sign in to comment.