note 77853 deleted from function.array-diff by bjori

From: Date: Mon, 17 Sep 2007 12:57:03 +0000
Subject: note 77853 deleted from function.array-diff by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130550@lists.php.net to get a copy of this message
Note Submitter: jakepaulus [at] gmail {dot} com ---- 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.

« previous php.notes (#130550) next »