How to use array keys in PHP

In this article, I will explain how the array_keys() function can be used in PHP.
  • 1667

array_keys() function in PHP

  • The array_keys() function returns an array containing the keys.

  • The array_keys() function returns the keys as numeric and string from the input array.

  • The array_keys() function is used to get all the keys of an array.

Syntax

array_keys(array,value)

Parameter

  • array  array is required parameter. Specifies an array.

  • value value is optional parameter. You can specify a value. value to be checked.

Example

The following example show to how the array_keys() function can be used in PHP.

<html>

<body>

<h3 style="color: darkslateblue;">array_keys() function example in PHP</h3>

    <?php

    $a=array("a"=>"student","b"=>"teacher","c"=>"advocate");

    print_r(array_keys($a));

 

    $a=array("a"=>"student","b"=>"teacher","c"=>"advocate");

    print_r(array_keys($a,"student"));

 

    $a=array(10,20,30,"10");

    print_r(array_keys($a,"10",false));

    ?>

</body>

</html>

 

Output

keys.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.