array = array_keys ($input_array, $search_str,$strict);
| Parameter | DESCRIPTION |
|---|---|
| $input_array | Required : Input array to be searched. |
| $search_str | Optional: Values to be searched inside $input_array. |
| $strict | Optional: FALSE ( default): strict comparison is not done. TRUE comparison of type of variable is done. |
$ar=array("SName"=>"Ronald","Class"=>"Fourth","Subject"=>"Science","Game"=>"Cricket");
$kar=array_keys($ar);
print_r($kar);
The output is here
Array ( [0] => SName [1] => Class [2] => Subject [3] => Game )
We can pass a value (of element ) and get the respective key like this
$ar=array("SName"=>"Ronald","Class"=>"Fourth","Subject"=>"Science","Game"=>"Cricket");
$kar=array_keys($ar,'Fourth');
print_r($kar);
We will get a single element array returning the key Output is here
Array ( [0] => Class )
$ar=array("SName"=>"Ronald","Class"=>"Fourth","Subject"=>"Cricket","Game"=>"Cricket");
$kar=array_keys($ar,'Cricket');
print_r($kar);
Output is here
Array ( [0] => Subject [1] => Game )
Two keys are returned in above case.
| Function | Details |
|---|---|
| in_array() | Search for value inside Array. Returns TRUE or FALSE |
| array_search() | Search for value inside Array. Returns the key if found, FALSE otherwise |
| array_key_exists() | Search for key inside Array. True if found, FALSE otherwise |
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.