I have a PHP array.
array
0 => int 1
1 => int 13
2 => int 16
3 => int 17
4 => int 18
What I want returned is a new array like this:
array(1, 13, 16, 17, 18)
ie. The values are now keys of a new array
I’ve tried array_flip, but I need to drop the values.
I’ve googled around and there doesn’t seem to anything that relates.
If someone could point me to the right direction or provide a better solution, it would be much appreciated.
EDIT:
array_flip returns:
array
1 => int 0
13 => int 1
16 => int 2
17 => int 3
18 => int 4
What I want is just: array(1, 13, 16, 17, 18).
Am I understanding this wrong? Does the output I want actually have null values on each key?
You seem to not understand how arrays work. Every array that contains at least one value always has a key(s) and a value(s). In the case of this:
the values are 1,13,16,… and the keys are implicitly set by PHP. In this case the value 1 has a key 0, value 13 has a key 1 and so on.
The only difference between your first and second array is that in the first you have keys defined explicitly. In short, the arrays are identical.