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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.