SQL PHP HTML ASP JavaScript articles and free scripts to download
 

array_keys to get the key of array

Arrays_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 )




Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Array Functions
PHP Sections