$arr = array();foreach ($arr as $key => $value) { if (!isset($key)) { echo 'haha'; }}
When the $key does not exist, the output is haha, but the actual operation why does nothing output?
Reply content:
$arr = array();foreach ($arr as $key => $value) { if (!isset($key)) { echo 'haha'; }}
When the $key does not exist, the output is haha, but the actual operation why does nothing output?
No access to foreach
$key
How is it that there is no way to be traversed?
Logic problem, definitely can't get into if
First the array is empty, does not enter foreach, and second, there is no !isset($key)
case
Upstairs is right, your array is empty, the program will not enter the Foreach loop.
$arr has a value and does not enter the IF
$arr = array('key1'=>'hello',3,4=>'34',4);foreach ($arr as $key => $value) { if (!isset($key)) { echo 'haha'; }else{ echo $key.' '; }}//print: key1 0 4 5