Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

array_keys()

List every key, or supply a value to list only its matching keys.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

array_keys(array $array): array
array_keys(array $array, mixed $filter_value, bool $strict = false): array

List every key, or supply a value to list only its matching keys. The third argument enables comparison of both type and value. With loose comparison a number and its numeric string can match together. The returned list contains keys in source order, making it useful for identifying all matching fields.

Signature

array_keys(array $array): array
array_keys(array $array, mixed $filter_value, bool $strict = false): array

Example output

[["units","code"],["units"]]

Examples

<?php
$row = ['units'=>2, 'code'=>'2', 'extra'=>3];
echo json_encode([array_keys($row, 2), array_keys($row, 2, true)]);

Result

[["units","code"],["units"]]

Sources