Odd thing with a very simple code
Posted: Thu Feb 10, 2011 2:49 pm
Hi there.
I'm testing a very simple code. Basically I'm doing a foreach in an array which has no keys, there is only one field that has a key "email".
This is the code:
The odd thing is that the following sentence:
returns TRUE when $field is 0 (zero)
I solved the problem replacing the sentence for this one:
What I really like to know is why that sentence if ($field == 'email') { returns TRUE when $field is 0 ??
Thanks a lot!
I'm testing a very simple code. Basically I'm doing a foreach in an array which has no keys, there is only one field that has a key "email".
This is the code:
Code: Select all
$data_array = array($name0,$company0,'email'=>$email0,$comment);
foreach($data_array as $field=>$data) {
if ($field == 'email') {
echo 'current field is email';
}
else {
echo 'current field is not email';
}
}
Code: Select all
if ($field == 'email') {
I solved the problem replacing the sentence for this one:
Code: Select all
if ($field === 'email') { Thanks a lot!