I have an array and would like to find the object with maximal rating? My array looks like below:
Array
(
[0] => stdClass Object
(
[created_by] => 905
[rating] => 1
)
[1] => stdClass Object
(
[created_by] => 906
[rating] => 2
)
)
Thanks!
I have tried something like that:
static function maxValueInArray($array, $keyToSearch) {
$currentMax = NULL;
foreach($array as $arr) {
foreach($arr as $key => $value) {
if ($key == $keyToSearch && ($value >= $currentMax)) {
$currentMax = $value;
}
}
}
return $currentMax;
}