- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
array_keys() function in PHP
The array_keys() function returns all the keys of an array. It returns an array of all the keys in array.
Syntax
array_keys(arr, value, strict)
Parameters
arr − The array from which the keys will be returned
value − If the values are specified, then only the keys containing these values will be returned.
strict − Determines if strict comparison (===) should be used during the search.
Return
The array_keys() function returns an array of all the keys in array.
Example
<?php $arr = array("one" => "Pen", "two" => "Pencil", "three" => "Paper", "four" => "Notepad"); print_r(array_keys($arr)); ?>
Output
Array ( [0] => one [1] => two [2] => three [3] => four )
Example
Let us see another example wherein we will find the key for a specific value “Notepad”.
<?php $arr = array("one" => "Pen", "two" => "Notepad", "three" => "Paper", "four" => "Notepad"); print_r(array_keys($arr, "Notepad")); ?>
Output
Array ( [0] => two [1] => four )
Advertisements
To Continue Learning Please Login
Login with Google