Home >Backend Development >PHP Tutorial >php array_keys returns the key name of the array

php array_keys returns the key name of the array

高洛峰
高洛峰Original
2017-01-14 14:13:511193browse

array_keys returns some or all key names in the array

Description

array array_keys (array $array [, mixed $search_value [, bool $strict = false ]] )

array_keys() Returns the key name of the number or string in the $array array.

If the optional parameter search_value is specified, only the key name of the value will be returned. Otherwise all keys in the $array array will be returned.

Parameter details

php array_keys 返回数组的键名

Return value

Returns all keys in the array.

Example

<?php
$array = array( 0 => 100 , "color" => "red" );
 print_r ( array_keys ( $array ));
 
 $array = array( "blue" , "red" , "green" , "blue" , "blue" );
 print_r ( array_keys ( $array , "blue" ));
 
 $array = array( "color" => array( "blue" , "red" , "green" ),
        "size"  => array( "small" , "medium" , "large" ));
 print_r ( array_keys ( $array ));
 ?>

The above routine will output:

Array ( [0] => 0 [1] => color ) Array ( [0] => ; 0 [1] => 3 [2] => 4 ) Array ( [0] => color [1] => size )

Thank you for reading, I hope it can help everyone, thank you Thank you for your support of this site!

For more articles related to php array_keys returning the key name of the array, please pay attention to the PHP Chinese website!

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