note 106833 added to function.array-fill-keys
| From: | comments at htmlcompressor dot com | Date: | Sat, 10 Dec 2011 14:30:55 +0000 |
| Subject: | note 106833 added to function.array-fill-keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185011@lists.php.net to get a copy of this message | ||
I needed a PHP4 compatible version which behaves as expected from the PHP5 version. I tried the ones
contributed by other users here but they do fail to comply, so I made the following function:
<?php
if (!function_exists('array_fill_keys')) {
function array_fill_keys($keys, $value) {
if (!is_array($keys)) {
trigger_error('array_fill_keys() expects parameter 1 to be array, ' .
gettype($keys) . ' given', E_USER_WARNING);
return;
}
$filled_array = array();
foreach($keys as $key) {
$filled_array[$key] = $value;
}
return $filled_array;
}
}
?>
----
Server IP: 192.41.42.26
Probable Submitter: 173.239.7.84
----
Manual Page -- http://www.php.net/manual/en/function.array-fill-keys.php
Edit -- https://master.php.net/note/edit/106833
Del: integrated -- https://master.php.net/note/delete/106833/integrated
Del: useless -- https://master.php.net/note/delete/106833/useless
Del: bad code -- https://master.php.net/note/delete/106833/bad+code
Del: spam -- https://master.php.net/note/delete/106833/spam
Del: non-english -- https://master.php.net/note/delete/106833/non-english
Del: in docs -- https://master.php.net/note/delete/106833/in+docs
Del: other reasons-- https://master.php.net/note/delete/106833
Reject -- https://master.php.net/note/reject/106833
Search -- https://master.php.net/manage/user-notes.php