i have a while loop, it goes like so….
while ($fruit_name = current($data)) {
$string1 .= "'".key($data)."',";
next($data);
}
this works perfectly, and echos:
'derp','test'
when the array data =
Array ( [derp] => 68 [test] => 1 )
but, if the array data =
Array ( [derp] => 0 [test] => 0 )
it echos
nothing,
what do?
If you want to traverse an array manually, you must use
eachsince there is – as you found out – no way to differentiate the negative result fromcurrentand a false-valued value. Even if you were to check with=== false, you’d still fail if the array contained afalseentry.However, you should really just use
foreachinstead: