I have an array of objects, and i want to sum value of one of the properties, example:
Array
(
[0] => stdClass Object
(
[name] => jon
Let's say $arr stores your information. Implement the following function:
function sumProperties(array $arr, $property) {
$sum = 0;
foreach($arr as $object) {
$sum += isset($object->{$property}) ? $object->{$property} : 0;
}
return $sum;
}
After that you just have to call sumProperties($array, 'commission')
.
Furthermore if you have more properties that could be summed, you could replace commission with those properties.