note 122594 deleted from function.array-merge by salathe

From: Date: Mon, 06 Sep 2021 22:48:16 +0000
Subject: note 122594 deleted from function.array-merge by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216918@lists.php.net to get a copy of this message
Note Submitter: matias dot r dot ventura at gmail dot com ---- Note that if you want to append one array to another, using a foreach in conjuction with array_push is A LOT faster: <?php $array = array("one", "two", "three", "four"); $test1 = array(); $test2 = array(); $mctime = microtime(true); for($i = 0; $i < 10000; $i++){ $test1 = array_merge($test1, $array); } echo("Test 1: ". (microtime(true) - $mctime) ."s "); $mctime = microtime(true); for($i = 0; $i < 10000; $i++){ foreach($array as $value){ array_push($test2, $value); } } echo("Test 2: ". (microtime(true) - $mctime) ."s "); ?> This in my case resolves to: Test 1: 2.7962880134583s Test 2: 0.0039298534393311s

« previous php.notes (#216918) next »