php array_keys returns the key name of the array

高洛峰
Release: 2023-03-04 19:48:01
Original
1178 people have browsed it

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 ));
 ?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!