Voting

: two plus three?
(Example: nine)

The Note You're Voting On

Prabhas Gupte
10 years ago
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".

<< Back to user notes page

To Top