When I run the code below I get "undefinied offset 4
" (or 5) error in the line:
if ($photo_type == '10') $ifile = $img[4]; else $ifile = $img[5];
However,
echo "$img[4]<br />$img[5]";
shows both - $img[4]
and $img[5]
. Why do I get "undefinied offset" error?
$imagedata = explode("|", $images);
$num_images = count($imagedata);
foreach($imagedata as $image) {
$img = explode(":", $image);
if ($photo_type == '10') $ifile = $img[4]; else $ifile = $img[5];
echo "$img[4]<br />$img[5]";
}
print_r($img);
Array ( [0] => 6403 [1] => 2 [2] => 1 [3] => c [4] => file1.jpg )
I can not use "list" because sometimes there is 5th value and sometimes not. When 5th value doesn't exist, I get "undefinied offset" error again.