i have this situation:
print_r($key);echo'<br>';
foreach($value as $test){
print_r(count($test));echo'<br>';
}
echo'<br>';
witch returns:
Jerome Frier
2
5
1
Luke Saora
5
4
6
Tracy Edion
6
1
4
what i am aiming for is to display the maximum value for each name, like this:
Jerome Frier Luke Saora Tracy Edion
6 5 6
basically taking the maximum value for each name comparing each row..
does this sound confuse... :)
thanks
If I were you I'd just make use of PHP's max function. If the first and only parameter is an array, max() returns the highest value in that array. If at least two parameters are provided, max() returns the biggest of these values.
So either you put all the values in an array and throw it into the max()
function, or you insert them one by one..
$max = max($your_values); //where $your_values is an array
//or
$max = max($value1, $value2, $value3); //where $value is a single value
So it seems as if there are two nested foreach loops, am i right?
Maybe you try this out, it´s not tested but anyways:
$array = $your_array;
$compare = array();
foreach($array as $key => $personScoreArray){
$compare[$key] = max($personScoreArray);
}
Then you can do what ever you want with the values in the $compare array. For a better solution a bit more code or a more spcific question would be nice.
I think this is what you're after (assuming $arr
is your outer array):
$result = array();
foreach ($arr as $key => $value) {
echo $key . '<br />' . max($value) . '<br /><br />';
}