I'm working on a project that involves extracting Red, green and blue values from an image and finding the maximum value of red values, green values and blue values. When I upload an image that doesn't contain red values I got this error message: Undefined offset. The same message appears if image doesn't contain green or blue values. I used empty() to check if array is empty but it didn't help.
my code:
for($j1=0;$j1<=$red_count;$j1++){
if (empty($reds)){
$reds[$j1]=0;
}
if ($reds[$j1]>=$red_max){
$red_max = $reds[$j1];
}
}
for($j2=0;$j2<=$blue_count;$j2++){
if (empty($blues)){
$blues[$j2]=0;
}
if ($blues[$j2]>=$blue_max){
$blue_max = $blues[$j2];
}
}
for($j3=0;$j3<=$green_count;$j3++){
if (empty($greens)){
$greens[$j3]=0;
}
if ($greens[$j3]>=$green_max){
$green_max = $greens[$j3];
}
}