Home  >  Article  >  Backend Development  >  PHP array introductory tutorial array_keys() function

PHP array introductory tutorial array_keys() function

WBOY
WBOYOriginal
2016-07-25 08:57:521031browse
This article introduces the usage of the array_keys() function in PHP arrays. Friends in need can refer to it.

In php array functions, array_keys() function returns an array containing all the keys found in the searched array.

The form is as follows: array array_keys(array array[,mixed search_value])

If the optional parameter search_value is included, only keys matching that value will be returned.

Example that will output all arrays found in the $fruit array:

<?php
$fruits["apple"] = "red";  
$fruits["banana"] = "yellow";  
$fruits["watermelon"]="green";  
$keys = array_keys($fruits);  
print_r($keys);  //by bbs.it-home.org
  
//Array ( [0] => apple [1] => banana [2] => watermelon )
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn