PHP array_keys() Function

PHP array_keys() Function is used to get keys from array. PHP array_keys() function is PHP built-in function.

Syntax :

array_keys(array $array, mixed $search, bool $strict = false);

Parameter,

$array : Required. It is input array.

$search : Optional. It is value to find keys which containing this value.

$strict : Optional. Default value is false. If true, checks identical type of the value.

Return : It returns array containing keys from input array.

Let's see below example to understand php array_keys() Function in details.

Example :

<?php
$array=array("Samsung"=>"M30s","MI"=>"Note 8 pro","iPhone"=>"12 pro","Nokia"=>"X20");
echo "<br>It returns array containing the keys of ".'$array <br>';
$array_keys = array_keys($array);
print_r($array_keys);
echo "<br><br>It returns array containing the key for searched value. <br>";
$array_keys = array_keys($array,"12 pro");
print_r($array_keys);
?>

Comments

Leave a Reply

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

63140