note 40808 added to function.array-combine

From: Date: Mon, 15 Mar 2004 17:37:45 +0000
Subject: note 40808 added to function.array-combine
Groups: php.notes 
Request: Send a blank email to php-notes+get-66871@lists.php.net to get a copy of this message
One thing to note about all of the array_combine replacements below is that none of them quite mirror the behavior right - half_life_fool's is close, but it doesn't return false if there are empty arrays. The one I'm using is a slight modification of a couple of them - I tested a few with 3000 iterations, and it's slightly faster on average as well. Also, methods using next() are slower for some reason, even if you reduce it to one call for each array per loop. Probably the small call overhead. <?php function array_combine($array_keys, $array_values) { $t = array(); $size = count($array_keys); if (($size != count($array_values)) || ($size == 0)) return false; for ($x = 0, $key = array_values($array_keys), $value = array_values($array_values); $x < $size; $x++) { $t[$key[$x]] = $value[$x]; } return $t; } ?> I thought about allowing return-by-reference ala half_life_fool's, but I'm not sure what the point would be, as there's no speed gain and you can't use the properties of a reference for anything useful. ---- Manual Page -- http://www.php.net/manual/en/function.array-combine.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40808 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40808&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40808&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#66871) next »