W3Schools.com

PHP array_keys() Function


PHP Array Reference Complete PHP Array Reference

Definition and Usage

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

Syntax

array_keys(array,value)

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. Used with the value parameter. 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 1

<?php
$a=array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
print_r(array_keys($a));
?>

The output of the code above will be:

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


Example 2

Using the value parameter.

<?php
$a=array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
print_r(array_keys($a,"Dog"));
?>

The output of the code above will be:

Array ( [0] => c)


Example 3

Using the strict parameter: false

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

The output of the code above will be:

Array ( [0] => 0 [1] => 3 )


Example 4

Using the strict parameter: true

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

The output of the code above will be:

Array ( [0] => 3)


PHP Array Reference Complete PHP Array Reference

W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 10 000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE