note 79132 added to function.array-key-exists

From: Date: Tue, 13 Nov 2007 08:18:42 +0000
Subject: note 79132 added to function.array-key-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-132218@lists.php.net to get a copy of this message
array_diff can be very slow when the arrays are big. If all you need is to check which elements in array1 are not KEYS in array2, DON'T use: <?php array_diff($array1,array_keys($array2)) ?> A much quicker option is: <?php foreach ($array1 as $key=>$value) { if (isset($array2[$key])) unset($array1[$key]); } ?> On my computer, when $array1 has a single element and $array2 has 2600 elements, option 1 takes 50 milli-seconds, and option 2 takes 50 micro-seconds (1000 times less!). ---- Server IP: 82.80.248.162 Probable Submitter: 89.139.163.177 ---- Manual Page -- http://www.php.net/manual/en/function.array-key-exists.php Edit -- https://master.php.net/note/edit/79132 Del: integrated -- https://master.php.net/note/delete/79132/integrated Del: useless -- https://master.php.net/note/delete/79132/useless Del: bad code -- https://master.php.net/note/delete/79132/bad+code Del: spam -- https://master.php.net/note/delete/79132/spam Del: non-english -- https://master.php.net/note/delete/79132/non-english Del: in docs -- https://master.php.net/note/delete/79132/in+docs Del: other reasons-- https://master.php.net/note/delete/79132 Reject -- https://master.php.net/note/reject/79132 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132218) next »