php - Getting Max Value from an array -
hi trying use api postcodeanywhere calcuates total travel time , distance particular journey, , have got working using following code:
//build url request $url = "http://services.postcodeanywhere.co.uk/distancesanddirections/interactive/directions/v2.00/xmla.ws?"; $url .= "&key=" . urlencode($key); $url .= "&start=" . urlencode($start); $url .= "&finish=" . urlencode($finish); $url .= "&distancetype=" . urlencode($distancetype); //make request postcode anywhere , parse xml returned $file = simplexml_load_file($url); //check error, if there 1 throw exception if ($file->columns->column->attributes()->name == "error") { throw new exception("[id] " . $file->rows->row->attributes()->error . " [description] " . $file->rows->row->attributes()->description . " [cause] " . $file->rows->row->attributes()->cause . " [resolution] " . $file->rows->row->attributes()->resolution); } //copy data if ( !empty($file->rows) ) { foreach ($file->rows->row $item) { $data[] = array('segmentnumber'=>$item->attributes()->segmentnumber,'stepnumber'=>$item->attributes()->stepnumber,'action'=>$item->attributes()->action,'description'=>$item->attributes()->description,'road'=>$item->attributes()->road,'steptime'=>$item->attributes()->steptime,'stepdistance'=>$item->attributes()->stepdistance,'totaltime'=>$item->attributes()->totaltime,'totaldistance'=>$item->attributes()->totaldistance); $totaldistance = ($item["totaldistance"] * 0.000621371192); echo $totaldistance."<br>";
which results in following screenshot
the problem having echo shows displaying distance each journey step, whereas want max value.
i have tried $totaldistance = max($item["totaldistance"])
. following error:
max(): when 1 parameter given, must array
any appreciated.
you can max value:
$value = max($array);
Comments
Post a Comment