Permalink
Browse files

Update docs for Hash::apply()

  • Loading branch information...
markstory committed Dec 17, 2012
1 parent f2d1eba commit f326058a6d9a3de57adeaee71abed1bd886eba44
Showing with 11 additions and 0 deletions.
  1. +11 −0 lib/Cake/Utility/Hash.php
View
@@ -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.

0 comments on commit f326058

Please sign in to comment.