The problem is that max()
doesn't always behave as you would expect when using multidimensional arrays.
This code does the processing in two stages, first finds the max value. As this is only a 2 dimensional simple array, you can use...
$max = max(array_map("max", $hex_splited));
This applies max to each of the sub arrays and then gets the max of those values.
So in your case, this will be 'FE'
. Then as part of the loop which converts the data to decimal, it compares the original value with the max already found and stores the key...
$key = 0;
for ($i=0; $i < $count2; $i++) {
$inn_count = count($hex_splited[$i]);
for ($j=0; $j < $inn_count; $j++) {
$val = hexdec($hex_splited[$i][$j]);
$arr_rgb[$i][$j] = $val;
// Check if found the max value
if ( $max == $hex_splited[$i][$j] ) {
$key = $i;
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…