note 70961 added to function.in-array

From: Date: Mon, 06 Nov 2006 18:07:55 +0000
Subject: note 70961 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-119430@lists.php.net to get a copy of this message
I don't know if this is by design or not, but in_array() does not work with associative hashes: <?php $Test = Array("my_var" => 2); print_r($Test); echo "\n"; var_dump(in_array("my_var", $Test)); ?> Outputs: Array ( [my_var] => 2 ) bool(false) The workaround is to use array_key_exists() instead: <?php $Test = Array("my_var" => 2); print_r($Test); echo "\n"; var_dump(array_key_exists("my_var", $Test)); ?> Outputs: Array ( [my_var] => 2 ) bool(true) ---- Server IP: 216.194.113.175 Probable Submitter: 67.172.82.185 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/70961 Del: integrated -- https://master.php.net/note/delete/70961/integrated Del: useless -- https://master.php.net/note/delete/70961/useless Del: bad code -- https://master.php.net/note/delete/70961/bad+code Del: spam -- https://master.php.net/note/delete/70961/spam Del: non-english -- https://master.php.net/note/delete/70961/non-english Del: in docs -- https://master.php.net/note/delete/70961/in+docs Del: other reasons-- https://master.php.net/note/delete/70961 Reject -- https://master.php.net/note/reject/70961 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119430) next »