note 77853 added to function.array-diff

From: Date: Sun, 16 Sep 2007 02:35:14 +0000
Subject: note 77853 added to function.array-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-130529@lists.php.net to get a copy of this message
I believe array_diff() has an enormous amount of overhead. For example, the following caused a page to timeout where there were more than 500 static IPs in a subnet. <?php while($static_ip = mysql_fetch_row($results)){ $ipspace = array_diff($ipspace, $static_ip); } ?> I found the following code to work MUCH better: <?php $statics = array(); while($static_ip = mysql_fetch_row($results)){ array_push($statics, $static_ip['0']); } $ipspace = array_diff($ipspace, $statics); ?> This allows my script to execute in about 0.33 seconds instead of over 30 seconds. ---- Server IP: 209.41.74.194 Probable Submitter: 69.138.133.8 ---- Manual Page -- http://www.php.net/manual/en/function.array-diff.php Edit -- https://master.php.net/note/edit/77853 Del: integrated -- https://master.php.net/note/delete/77853/integrated Del: useless -- https://master.php.net/note/delete/77853/useless Del: bad code -- https://master.php.net/note/delete/77853/bad+code Del: spam -- https://master.php.net/note/delete/77853/spam Del: non-english -- https://master.php.net/note/delete/77853/non-english Del: in docs -- https://master.php.net/note/delete/77853/in+docs Del: other reasons-- https://master.php.net/note/delete/77853 Reject -- https://master.php.net/note/reject/77853 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130529) next »