Somtimes you have a quite big array which is filled up from a file or code. In this case you don't know whether a given value exists in the array or not. And if it exists then it would be fine to get the key of this element.
Let's suppose you have the following array:
Code:
$colorList = array("apple"=>"red",
"grass"=>"green",
"sky"=>"blue",
"night"=>"black",
"wall"=>"white");
Now if you want to know whether the value "blue" exists you can use the PHP built in function array_search(). With this you can easy get this information in the following way:
Code:
echo 'Blue is '.array_search("blue",$colorList);
No comments:
Post a Comment