Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

array_keys()

Example

The array_keys() function returns an array containing the keys of a given array.

<?php
$a=array(“Volvo”=>“XC90”,“BMW”=>“X5”,“Toyota”=>“Highlander”);
print_r(array_keys($a));
?>

Definition and Usage

The array_keys() function returns an array of the keys.

Syntax

array_keys(array, value, strict)

Parameter Values

Parameter

Description

array

Required. Specifies the array.

value

Optional. If a value is specified, only the keys corresponding to that value are returned.

strict

Optional. Used with the value parameter. Possible values:

  • true – Returns the keys with the specified value, considering type (e.g., the number 5 is not the same as the string “5”).
  • false – Default value. Does not consider type (e.g., the number 5 is considered the same as the string “5”).

Technical Details

 

Return Value:

Returns an array of the keys.

PHP Version:

4+

Changelog:

The strict parameter was introduced in PHP 5.0.

More Examples

Example

When using the value parameter:

<?php
$a=array(“Volvo”=>“XC90”,“BMW”=>“X5”,“Toyota”=>“Highlander”);
print_r(array_keys($a,“Highlander”));
?>

Example

When using the strict parameter set to false:

<?php
$a=array(10,20,30,“10”);
print_r(array_keys($a,“10”,false));
?>

Example

When using the strict parameter set to true:

<?php
$a=array(10,20,30,“10”);
print_r(array_keys($a,“10”,true));
?>