PHP get first key in associative array

If efficiency is not that important can use array_keys($yourArray)[0] in PHP 5.4 (and higher).

	$arr = array('a'=>1, 'b'=>2, ....)
	$keys   =   array_keys($arr);
	echo $keys[0];

Output: a

By Keenlio, August 7, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


7 + seven =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>