There is an associative array with only one pair key=>value
.
I don't know it's key, but I need to get it's value:
$array = array('???' => 'value');
$value = // ??
$array[0]
doesn't work.
How can I get it's value?
There is an associative array with only one pair key=>value
.
I don't know it's key, but I need to get it's value:
$array = array('???' => 'value');
$value = // ??
$array[0]
doesn't work.
How can I get it's value?
You should use array_values
array_keys()
will get the key for youWhat you want is to retrieve the first item?
You can also do either of the following functions to get the value since there's only one element in the array.
Also, if you want to use
array_keys()
, you'd need to do:To get the value.
As some more options, you can ALSO use
array_pop()
orarray_shift()
to get the value:Finally, you can use
array_values()
to get all the values of the array, then take the first:Of course, there are lots of other alternatives; some silly, some useful.