note 118570 added to function.array-walk

From: Date: Wed, 30 Dec 2015 09:01:56 +0000
Subject: note 118570 added to function.array-walk
Groups: php.notes 
Request: Send a blank email to php-notes+get-204566@lists.php.net to get a copy of this message
Correction for the speed test from zlobnygrif. <?php // Test results $array1 = test('array_walk'); $array2 = test('array_walk_list_each'); $array3 = test('array_walk_foreach1'); $array4 = test('array_walk_foreach2'); // Check arrays for equal var_dump($array1 == $array2, $array1 == $array3, $array1 == $array4); // Test function 1 function array_walk_list_each(&$array, $function, $userData = null) { /* make sure we walk the array each time */ reset($array); while ( list($key, $value) = each($array) ) $function($array[$key], $key, $userData); } // Test function 2 function array_walk_foreach1(&$array, $function, $userData = null) { foreach ($array as $key => &$value ) $function($value, $key, $userData); } // Test function 3 function array_walk_foreach2(&$array, $function, $userData = null) { foreach ($array as $key => $value ) $function($array[$key], $key, $userData); } function some_function(&$value, $key, $userData) { $value = "$key => $userData"; } function test($function, $count = 10000, $arrayElements = 1000) { echo $function, ' ... '; $array = array_fill(0, $arrayElements, "some text value"); $timer = microtime(true); for( $i = 0; ++$i < $count; ) /* change data for each $i */ $function($array, 'some_function', 'some user data ' . $i); printf("%.3f sec\n", microtime(true) - $timer); return $array; } ---- Server IP: 72.52.91.14 Probable Submitter: 75.171.154.141 ---- Manual Page -- http://php.net/manual/en/function.array-walk.php Edit -- https://master.php.net/note/edit/118570 Del: integrated -- https://master.php.net/note/delete/118570/integrated Del: useless -- https://master.php.net/note/delete/118570/useless Del: bad code -- https://master.php.net/note/delete/118570/bad+code Del: spam -- https://master.php.net/note/delete/118570/spam Del: non-english -- https://master.php.net/note/delete/118570/non-english Del: in docs -- https://master.php.net/note/delete/118570/in+docs Del: other reasons-- https://master.php.net/note/delete/118570 Reject -- https://master.php.net/note/reject/118570 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#204566) next »