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 )

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Your Rating


Google+

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer