note 72158 deleted from function.array-fill-keys by betz
| From: | betz@php.net | Date: | Fri, 21 Mar 2008 10:38:10 +0000 |
| Subject: | note 72158 deleted from function.array-fill-keys by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137257@lists.php.net to get a copy of this message | ||
Note Submitter: php dot spam at phihag dot de
----
A better(presumably faster, easier to write) substitute (for php >= 5) is:
<?php
if (! function_exists("array_fill_keys")) {
function array_fill_keys(array $keys, $value) {
return array_combine($keys, array_fill(0, count($keys), $value));
}
}
// simple testcase
(array_fill_keys(array(1, 3, 2, "a", "b"), 42) === array(1 => 42, 3 => 42,
2 => 42, "a" => 42, "b" => 42)) or die("testcase 1 of
array_fill_keys failed.");
?>