php - Find highest max() of mixed array -


ive got array outputted db

array      (         [0] => array             (                 [name] => fernando alonso                 [time1] => 3.25                 [time2] => 3.25                 [time3] => 3.5             )          [1] => array             (                 [name] => jenson button                 [time1] => 34                 [time2] => 41                 [time3] => 41             )     ) 

what want each driver output name , fastest time somthing

fernando alsonso, time3 - 3.5

jenson button, time2, time3 - 41

i playing around using max() having trouble getting work having trouble first element string, rather int / num,

any idea how write function ?

okay here go, right try max()

function get_highest_time($driver) {     // first find highest time     $highest_time = max($driver['time1'], $driver['time2'], $driver['time3']);     // find of array keys match time     $times = array_keys($driver, $highest_time);     // turn array of keys string , add highest time end     return implode(', ', $times) . ' - ' . $highest_time; }  foreach ($arr $driver) { // $arr array of drivers     print $driver['name'] . ': ' . get_highest_time($driver) . '<br />'; } 

edit:

just noticed said want driver's fastest time, surely lowest number? if case swap max() min()


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -