note 103690 added to control-structures.foreach
| From: | Grzegorz at osu1 dot php dot net | Date: | Thu, 28 Apr 2011 10:15:21 +0000 |
| Subject: | note 103690 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179223@lists.php.net to get a copy of this message | ||
Hello Everyone
Just wanted to point smth interesting i found out.
$id = '3047';
$array = array (
'3047' => '',
'3049' => '',
'3074' => ''
);
As you can see, all key's are numers but in string form.
foreach ($przedmioty as $key => $val){
echo var_dump ($id);
echo var_dump ($key);
die();
}
Will output
string(4) "3066"
int(3047)
Foreach tries to convert key to int, if it succedes $key is reurned as int. (haven't tested
double)
Thus, you can't compare string with it with === operator. Tried to compare it with get to
exclude which key shouln't be generated
----
Server IP: 69.147.83.197
Probable Submitter: 83.28.46.66
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/103690
Del: integrated -- https://master.php.net/note/delete/103690/integrated
Del: useless -- https://master.php.net/note/delete/103690/useless
Del: bad code -- https://master.php.net/note/delete/103690/bad+code
Del: spam -- https://master.php.net/note/delete/103690/spam
Del: non-english -- https://master.php.net/note/delete/103690/non-english
Del: in docs -- https://master.php.net/note/delete/103690/in+docs
Del: other reasons-- https://master.php.net/note/delete/103690
Reject -- https://master.php.net/note/reject/103690
Search -- https://master.php.net/manage/user-notes.php