I've come across an old app that uses an id to name type array, for example...
array(1) {
[280]=>
string(3) "abc"
}
Now I need to reorder these, and a var_dump()
would make it appear that that isn't going to happen whilst the keys are integers.
If I add an a
to every index, var_dump()
will show double quotes around the key, my guess to show it is now a string (this sort of array is called a hash table in other languages I believe)...
array(1) {
["280a"]=>
string(3) "abc"
}
This would let me easily reorder them, without having to touch more code.
Is there a way to force the keys to be strings, so I can reorder them without ruining the array?
Thanks!
Update
This does not work.
$newArray = array();
foreach($array as $key => $value) {
$newArray[(string) $key] = $value;
}
A var_dump()
still shows them as integer array indexes.
Update
OK, I've decided not to wait this out and have changed how this works to something like this...
array(1) {
[0]=>
array(2) {
["name"] => string(3) "abc"
["id"] => int(280)
}
}
Then I had to modify some more code, to suit.
What I'm asking may be impossible, but I will leave this question here as someone may have a solution.