note 72557 deleted from function.array-values by crell

From: Date: Tue, 12 Apr 2022 01:06:18 +0000
Subject: note 72557 deleted from function.array-values by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218195@lists.php.net to get a copy of this message
Note Submitter: ahigerd at stratitec dot com ---- 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

« previous php.notes (#218195) next »