note 60979 deleted from language.references by philip

From: Date: Thu, 03 Sep 2015 02:33:26 +0000
Subject: note 60979 deleted from language.references by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203600@lists.php.net to get a copy of this message
Note Submitter: Slava Kudinov <skudinov gmail com> ---- In addition to the "array vs &array" example below, php 5.1.2. It seems passing an array by reference slower than by value, consider: <?php function test_ref(&$arr) { $size = sizeof($arr); for($n=0; $n<$size; $n++) { $x = 1; } } function test_val($arr) { $size = sizeof($arr); for($n=0; $n<$size; $n++) { $x = 1; } } // fill array for($n=0; $n<2000; $n++) { $ar[] = "test".$n; } $time = microtime(); test_ref($ar); echo "<br />The function using a reference took ".(microtime() - $time)." s"; $time = microtime(); test_val($ar); echo "<br />The funktion using a value took: ".(microtime() - $time)." s"; echo "<br />Done"; ?> output: The function using a reference took 0.002694 s The funktion using a value took: 0.000847 s

« previous php.notes (#203600) next »