PHP Array get key from value
This section illustrates how to get the key from the array for the given value
This section illustrates how to get the key from the array for the given value
- In php array one can get the key from value by the use of
array_search function
- Array_search function searches the key for the given values in
the array.
Example of PHP Array Get Key from Value
<?php
$product=
array(
"n"=>
"newyork",
"c"=>
"cylone",
"t"=>
"tokyo",
"New Delhi",
"d"=>
"dhaka");
$k=array_search(
"cylone",
$product);
echo "key of cylone is ".
$k;
?>
Output
key of cylone is c