note 111173 added to function.array-combine
| From: | aaron at aaronholmes dot net | Date: | Tue, 22 Jan 2013 16:54:04 +0000 |
| Subject: | note 111173 added to function.array-combine | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-193345@lists.php.net to get a copy of this message | ||
You can create an array hashset from a flat array, storing both keys and values, with
array_combine(). This works with duplicate values in the array too.
<?php
$flat_array = array(
'one',
'two',
'three',
'three',
'four',
'one'
);
$set = array_combine($flat_array, $flat_array);
var_dump($set);
?>
This outputs the following:
array(4) {
["one"]=>
string(3) "one"
["two"]=>
string(3) "two"
["three"]=>
string(5) "three"
["four"]=>
string(4) "four"
}
----
Server IP: 192.41.42.26
Probable Submitter: 38.122.108.2
----
Manual Page -- http://php.net/manual/en/function.array-combine.php
Edit -- https://master.php.net/note/edit/111173
Del: integrated -- https://master.php.net/note/delete/111173/integrated
Del: useless -- https://master.php.net/note/delete/111173/useless
Del: bad code -- https://master.php.net/note/delete/111173/bad+code
Del: spam -- https://master.php.net/note/delete/111173/spam
Del: non-english -- https://master.php.net/note/delete/111173/non-english
Del: in docs -- https://master.php.net/note/delete/111173/in+docs
Del: other reasons-- https://master.php.net/note/delete/111173
Reject -- https://master.php.net/note/reject/111173
Search -- https://master.php.net/manage/user-notes.php