Last active
August 26, 2016 18:39
-
-
Save kristoferdoman/535348f64273db974addb668579ddf03 to your computer and use it in GitHub Desktop.
Php: Sum Property of an Object Collection in a Nested Object Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$object = new Object(); | |
$count = array_sum(array_map(function($x) { | |
$count = array_sum(array_map(function($y) { return count($y->propertyOfAnotherObject); }, $x->anotherObjectInsideObject)); | |
return $count; | |
}, $object)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: You can use this code to get the sum of all value properties, in every list object, inside every object "object".