English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_keys() function usage and examples

PHP Array Function Manual

The PHP array_keys() function returns partial or all key names in the array

Syntax

array_keys($input[, $search_value[, $strict]];)

Definition and Usage

array_keys() returns the key names of numbers or strings in the input array.
If the optional parameter search_value is specified, only return the key names of that value. Otherwise, all key names in the input array will be returned.

Parameter

Serial NumberParameters and Description
1

input(Required)

It specifies an array.

2

search_value(Required)

You can specify a value and only return keys with that value.

3

strict

Optional. Used with the value parameter.

Return value

It returns keys, numbers, and strings from the $input array

Online Example

Returns all keys and specified values in the array

<?php
   $input = array("a"=>"Monkey","b"=>"Cat","c"=>"Dog");
   print_r(array_keys($input));
   
   $input = array("a"=>"Monkey","b"=>"Cat","c"=>"Dog");
   print_r(array_keys($input,"Dog"));
   
   $input = array(10,20,30,"10");
   print_r(array_keys($input,"10",false));
?>
Test and see‹/›

Output result:

Array
(
    [0] => a
    [1] => b
    [2] => c
)
Array
(
    [0] => c
)
Array
(
    [0] => 0
    [1] => 3
)

PHP Array Function Manual