I have problem with 0th array element as output of FOR cycles. I want server to print letters A B C D E; and if something is different as element in array, than it should be printed something else. So I made conditions and switch statement for that.
But 0th element of array is always printed out as different element. I do not know what I am doing wrong. Can you please help me? Can you explain me why is this happening?
<?php
$array = array(0,1,2,3,4,"something");
for($i=0;$i<count($array);$i++){
echo '<br>'.$i;
if ($array[$i] == 'something') {
echo ' something ';
} else {
switch ($array[$i])
{ case "0":
echo ' A';
break;
case "1":
echo ' B';
break;
case "2":
echo ' C';
break;
case "3":
echo ' D';
break;
case "4":
echo ' E';
break;
default:;
};
};
};
?>
My output is this:
0 something
1 B
2 C
3 D
4 E
5 something
But I am expecting this:
0 A
1 B
2 C
3 D
4 E
5 something
reset($array)before your loop0in PHP, use===to stop this. You can test this yourself withvar_dump(0 == "hello");0 == 'something'first?