|
|
array_keys to get the key of arrayArrays_key function returns an array with all the keys as element. We can specify a value of the array and get the associated key for the element. We will start with some examples.
$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 )
| |
| | |
|
|
|
| Array Functions |
|
|
|
| PHP Sections |
|
|
|