note 116597 added to function.array-flip
| From: | PrabhasGupte | Date: | Tue, 27 Jan 2015 06:48:24 +0000 |
| Subject: | note 116597 added to function.array-flip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201535@lists.php.net to get a copy of this message | ||
array_flip() does not retain the data type of values, when converting them into keys. :(
<?php
$arr = array('one' => '1', 'two' => '2',
'three' => '3');
var_dump($arr);
$arr2 = array_flip($arr);
var_dump($arr2);
?>
This code outputs this:
array(3) {
["one"]=>
string(1) "1"
["two"]=>
string(1) "2"
["three"]=>
string(1) "3"
}
array(3) {
[1]=>
string(3) "one"
[2]=>
string(3) "two"
[3]=>
string(5) "three"
}
It is valid expectation that string values "1", "2" and "3" would
become string keys "1", "2" and "3".
----
Server IP: 72.52.91.14
Probable Submitter: 63.226.86.158
----
Manual Page -- http://php.net/manual/en/function.array-flip.php
Edit -- https://master.php.net/note/edit/116597
Del: integrated -- https://master.php.net/note/delete/116597/integrated
Del: useless -- https://master.php.net/note/delete/116597/useless
Del: bad code -- https://master.php.net/note/delete/116597/bad+code
Del: spam -- https://master.php.net/note/delete/116597/spam
Del: non-english -- https://master.php.net/note/delete/116597/non-english
Del: in docs -- https://master.php.net/note/delete/116597/in+docs
Del: other reasons-- https://master.php.net/note/delete/116597
Reject -- https://master.php.net/note/reject/116597
Search -- https://master.php.net/manage/user-notes.php