note 103690 deleted from control-structures.foreach by danbrown

From: Date: Thu, 28 Apr 2011 15:08:59 +0000
Subject: note 103690 deleted from control-structures.foreach by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179232@lists.php.net to get a copy of this message
Note Submitter: Grzegorz ---- 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

« previous php.notes (#179232) next »