Skip to content

Commit f326058

Browse files
committed
Update docs for Hash::apply()
1 parent f2d1eba commit f326058

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/Cake/Utility/Hash.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,17 @@ public static function reduce(array $data, $path, $function) {
698698
* Apply a callback to a set of extracted values using `$function`.
699699
* The function will get the extracted values as the first argument.
700700
*
701+
* ### Example
702+
*
703+
* You can easily count the results of an extract using apply().
704+
* For example to count the comments on an Article:
705+
*
706+
* `$count = Hash::apply($data, 'Article.Comment.{n}', 'count');`
707+
*
708+
* You could also use a function like `array_sum` to sum the results.
709+
*
710+
* `$total = Hash::apply($data, '{n}.Item.price', 'array_sum');`
711+
*
701712
* @param array $data The data to reduce.
702713
* @param string $path The path to extract from $data.
703714
* @return mixed The results of the applied method.

0 commit comments

Comments
 (0)