Skip to content

PHP Array Functions: key()

key (): Used to find the key of the element at the position of the pointer to the array.


	$ARRAY_LIST = ["maria","alex",array("rick","allen"),"jason","bob"];

	echo "<pre>";
	print_r($ARRAY_LIST);
	echo "</pre>";

	$ARRAY_LIST_KEY = key($ARRAY_LIST);
	echo $ARRAY_LIST_KEY;

0


	$ARRAY_LIST = ["key1" => "maria", "key2" => "alex","key3" => "jason","key4" => "bob"];

	echo "<pre>";
	print_r($ARRAY_LIST);
	echo "</pre>";

	$ARRAY_LIST_KEY = key($ARRAY_LIST);
	echo $ARRAY_LIST_KEY;

  Array  (      
[key1] => maria      
[key2] => alex      
[key3] => jason      
[key4] => bob  
)

key1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: