array_keys and array_key_exists

array_keys and array_key_exists

array_keys
This function will return all the keys of an array.

For example
$arr = array(”one”=>,”two”=>2,”three”=>3)
$temp = array_keys($arr);

print_r($arr);

Now the temporary array will contain
Array ( [0] => one [1] => two [2] => three )

$arr = array(”one”=>,”two”=>2,”three”=>3)

array_key_exists

This function is used to check whether array key is exists or not

Example
$arr = array(”one”=>1,”two”=>2,”three”=>3);
echo $temp = array_key_exists(”one”,$arr);
echo $temp = array_key_exists(”one1″,$arr);

First echo will print 1 because key one is exists in the array.And also second will print nothing because key one1 is not exists in the array.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.