note 98500 deleted from function.array-unique by danbrown

From: Date: Fri, 18 Jun 2010 23:57:21 +0000
Subject: note 98500 deleted from function.array-unique by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170256@lists.php.net to get a copy of this message
Note Submitter: michiel ed thalent nl ---- Then what is even faster is using array_flip. <?php $max = 1000000; $arr = range(1,$max,3); $arr2 = range(1,$max,2); $arr = array_merge($arr,$arr2); $time = -microtime(true); $res1 = array_unique($arr); $time += microtime(true); echo "deduped to ".count($res1)." in ".$time; // deduped to 666667 in 13.498242855072 $time = -microtime(true); $res2 = array(); $res2 = array_flip($arr); $res2 = array_keys($res2); $time += microtime(true); echo "<br />deduped to ".count($res2)." in ".$time; // deduped to 666667 in 0.37050104141235 $time = -microtime(true); $res3 = array(); foreach($arr as $key=>$val) { $res3[$val] = true; } $res3 = array_keys($res3); $time += microtime(true); echo "<br />deduped to ".count($res3)." in ".$time; // deduped to 666667 in 0.54348206520081 ?>

« previous php.notes (#170256) next »