note 93880 added to function.in-array

From: Date: Mon, 05 Oct 2009 07:53:45 +0000
Subject: note 93880 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-161342@lists.php.net to get a copy of this message
If you're creating an array yourself and then using in_array to search it, consider setting the keys of the array and using isset instead since it's much faster. <?php $slow = array('apple', 'banana', 'orange'); if (in_array('banana', $slow)) print('Found it!'); $fast = array('apple' => 'apple', 'banana' => 'banana', 'orange' => 'orange'); if (isset($fast['banana'])) print('Found it!'); ?> ---- Server IP: 212.63.193.10 Probable Submitter: 213.115.30.210 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/93880 Del: integrated -- https://master.php.net/note/delete/93880/integrated Del: useless -- https://master.php.net/note/delete/93880/useless Del: bad code -- https://master.php.net/note/delete/93880/bad+code Del: spam -- https://master.php.net/note/delete/93880/spam Del: non-english -- https://master.php.net/note/delete/93880/non-english Del: in docs -- https://master.php.net/note/delete/93880/in+docs Del: other reasons-- https://master.php.net/note/delete/93880 Reject -- https://master.php.net/note/reject/93880 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161342) next »