Trying to return the array where the key "distance" contains the maximum value, as opposed to just returning the value.
ie. from:
[0] => Array
(
[pid] => 1
[type] => lj
[distance] => 211849216
[maxspeed] => 277598944
...
)
[1] => Array
(
[pid] => 1
[type] => lj
[distance] => 230286752
[maxspeed] => 289118816
...
)
[2] => Array
(
[pid] => 1
[type] => lj
[distance] => 230840928
[maxspeed] => 298438336
...
)
...
I wish to get [2]:
(
[pid] => 1
[type] => lj
[distance] => 230840928
[maxspeed] => 298438336
...
)
I've been able to get the max value with the following:
function max_dist($a) {
return $a["distance"];
}
$jump = max(array_map("max_dist", $jumps)));
But unlike how elegantly simple it is with JS/underscore:
var jump=_.max(jumps,function(o){
return +o.distance;
});
it only returns the max distance value.
I have to just be missing something simple in PHP!