note 82941 added to function.array-fill-keys
| From: | Scratchy at osu1 dot php dot net | Date: | Fri, 02 May 2008 21:18:03 +0000 |
| Subject: | note 82941 added to function.array-fill-keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139006@lists.php.net to get a copy of this message | ||
RE: bananasims at hotmail dot com
I also needed a work around to not having a new version of PHP and wanting my own keys. bananasims
code doesn't like having an array as the second parameter...
Here's a slightly modified version than can handle 2 arrays as inputs:
//we want these values to be keys
$arr1 = (0 => "abc", 1 => "def");
/we want these values to be values
$arr2 = (0 => 452, 1 => 128);
function array_fill_keys($keyArray, $valueArray) {
if(is_array($keyArray)) {
foreach($keyArray as $key => $value) {
$filledArray[$value] = $valueArray[$key];
}
}
return $filledArray;
}
array_fill_keys($arr1, $arr2);
returns:
abc => 452, def =>128
----
Server IP: 64.71.164.2
Probable Submitter: 128.32.52.94
----
Manual Page -- http://www.php.net/manual/en/function.array-fill-keys.php
Edit -- https://master.php.net/note/edit/82941
Del: integrated -- https://master.php.net/note/delete/82941/integrated
Del: useless -- https://master.php.net/note/delete/82941/useless
Del: bad code -- https://master.php.net/note/delete/82941/bad+code
Del: spam -- https://master.php.net/note/delete/82941/spam
Del: non-english -- https://master.php.net/note/delete/82941/non-english
Del: in docs -- https://master.php.net/note/delete/82941/in+docs
Del: other reasons-- https://master.php.net/note/delete/82941
Reject -- https://master.php.net/note/reject/82941
Search -- https://master.php.net/manage/user-notes.php