note 87022 added to function.in-array

From: Date: Fri, 14 Nov 2008 22:39:01 +0000
Subject: note 87022 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-146573@lists.php.net to get a copy of this message
In response to the "Maybe the Fastest Recursive in_array yet?" post, I ran into a problem using it and needed to make the <?php $needle == $stalk ?> into <?php $needle === $stalk ?> because it was returning true on items that it shouldn't have. So, just for future reference, if someone is running into problems using this nice little php snippet, they may want to adjust it as such: <?php function recursive_in_array($needle, $haystack) { foreach ($haystack as $stalk) { if ($needle === $stalk || (is_array($stalk) && recursive_in_array($needle, $stalk))) { return true; } } return false; } ?> Thanks to the original poster, by the way. ---- Server IP: 208.69.120.35 Probable Submitter: 209.251.147.31 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/87022 Del: integrated -- https://master.php.net/note/delete/87022/integrated Del: useless -- https://master.php.net/note/delete/87022/useless Del: bad code -- https://master.php.net/note/delete/87022/bad+code Del: spam -- https://master.php.net/note/delete/87022/spam Del: non-english -- https://master.php.net/note/delete/87022/non-english Del: in docs -- https://master.php.net/note/delete/87022/in+docs Del: other reasons-- https://master.php.net/note/delete/87022 Reject -- https://master.php.net/note/reject/87022 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146573) next »