I want to identify the highest number for each place in an array of arrays. I think that the max function (http://www.php.net/manual/en/function.max.php) must be the one to use but I am having trouble getting it to work properly.
Here is the code for what I am trying to do. The data is being graphed on line charts and I want to determine the maximum values for scaling purposes.
// create query
$sql = "SELECT second, val1, val2, val3, val4, val5 FROM valtable WHERE (date_time = '$qdatetime' AND test_id = '$testid') ORDER BY second ASC";
$queryvals = odbc_exec($connectionstring, $sql);
// create two arrays of arrays with the data (each line item is an array of one second's worth of data)
$adata = array();
$bdata = array();
while($row = odbc_fetch_row($queryvals))
{
$sec = odbc_result($queryvals, "second");
$val1 = odbc_result($queryvals, "val1");
$val2 = odbc_result($queryvals, "val2");
$val3 = odbc_result($queryvals, "val3");
$val4 = odbc_result($queryvals, "val4");
$val5 = odbc_result($queryvals, "val5");
$apersecdata = array($sec, $val1, $val2, $val3);
array_push($adata,$apersecdata);
$bpersecdata = array($sec, $val4, $val5);
array_push($bdata,$bpersecdata);
}
// count arrays in each array
$howmanya = count ($adata);
$howmanyb = count ($bdata);
// determine maximum values
$maxval5 = max($bdata[$val5],0);
$maxval4 = max($bdata[$val4],0);
$maxval3 = max($adata[$val3],0);
$maxval2 = max($adata[$val2],0);
$maxval1 = max($adata[$val1],0);
$maxsec = max($adata[$sec],0);
The last section (determine maximum values) doesn't work right. Can anyone give me some guidance on how to find out the maximum values of each element in the array of arrays?