PHP's array_search()
does this:
Searches the array for a given value and returns the corresponding key if successful
I would like a function that does the exact opposite, that is, searches the array for a given key and returns the corresponding value if successful.
Is this available at all in PHP 5? If not, what solution would you suggest?
The array_reverse() function is used to reverse the order of the elements in an array.
The array_reverse() function returns an array in the reverse order.
PHP array_key_exists() Function The array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist.
Answer: Use the PHP array_reverse() function You can use the PHP array_reverse() function to reverse the order of the array elements.
I am confused. Would $array[$key]
not work?
You can just use square bracket syntax, as follows:
$arr = array("key" => "value");
$v = $arr["key"]; // returns "value"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With