why doesn't this php foreach return the value?
If you look at the code below, it doesn't echo anything out when the
return is in the if statement. When I take the return out, it echoes out
the correct value. Why is this?
$images= Array(
[0] => Array
(
[id] => 131],
[width] => 400]
),
[1] => Array
(
[id] => 140],
[width] => 900]
)
)
$array_key=0;
foreach($images as $key => $image){
if($image['id'] == $image_id){
$array_key= $key;
return;
}
}
echo $array_key;
No comments:
Post a Comment