note 72557 added to function.array-values

From: Date: Wed, 24 Jan 2007 14:07:10 +0000
Subject: note 72557 added to function.array-values
Groups: php.notes 
Request: Send a blank email to php-notes+get-122136@lists.php.net to get a copy of this message
A comment on array_merge mentioned that array_splice is faster than array_merge for inserting values. This may be the case, but if your goal is instead to reindex a numeric array, array_values() is the function of choice. Performing the following functions in a 100,000-iteration loop gave me the following times: ($b is a 3-element array) array_splice($b, count($b)) => 0.410652 $b = array_splice($b, 0) => 0.272513 array_splice($b, 3) => 0.26529 $b = array_merge($b) => 0.233582 $b = array_values($b) => 0.151298 ---- Server IP: 69.147.83.197 Probable Submitter: 75.19.79.5 ---- Manual Page -- http://www.php.net/manual/en/function.array-values.php Edit -- https://master.php.net/note/edit/72557 Del: integrated -- https://master.php.net/note/delete/72557/integrated Del: useless -- https://master.php.net/note/delete/72557/useless Del: bad code -- https://master.php.net/note/delete/72557/bad+code Del: spam -- https://master.php.net/note/delete/72557/spam Del: non-english -- https://master.php.net/note/delete/72557/non-english Del: in docs -- https://master.php.net/note/delete/72557/in+docs Del: other reasons-- https://master.php.net/note/delete/72557 Reject -- https://master.php.net/note/reject/72557 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122136) next »