PHP

PHP Menu

PHP

array_keys() Function - Definition, Syntax, Parameters, Examples

Definition

The array_keys() function returns all the keys or a subset of the keys of an array.

Syntax

array_keys(array, value, strict)

Parameters

Parameter Description
array Required. Specifies an array.
value Optional. You can specify a value, then only the keys with this value are returned.
strict Optional. Possible values: true - Returns the keys with the specified value, depending on type: the number 5 is not the same as the string "5"; false - Default value. Not depending on type, the number 5 is the same as the string "5".

Example

<?php
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); print_r(array_keys($ages)); echo "<br>";
// Using the `values` parameter print_r(array_keys($ages, 32)); echo "<br>";
// Using the `strict` parameter print_r(array_keys($ages, "32", false)); echo "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods