Tuesday, 11 June 2013

How to search a value in array in php

If you want to search an array in php and find it's corresponding key you can use in built array function.
array_search.

Example with Code and syntax :

<?php
$myarr=array("x"=>"Amol","y"=>"Sagar","z"=>"ganesh");

//search for Amol in myarr

echo (array_search("Amol",$myarr));

//This will print x

?>

This is how we can find the key corresponding to the value in php

No comments:

Post a Comment