PHP array_keys() 函数

PHP 教程 · 2019-01-22 09:58:46

实例

返回包含数组中所有键名的一个新数组:

<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a));
?>

定义和用法

array_keys() 函数返回包含数组中所有键名的一个新数组。

语法


array_keys(array,value,strict)


参数 描述
array 必需。规定数组。
value 可选。您可以指定键值,然后只有该键值对应的键名会被返回。
strict 可选。与 value 参数一起使用。可能的值:
  • true - 返回带有指定键值的键名。依赖类型,数字 5 与字符串 "5" 是不同的。
  • false - 默认值。不依赖类型,数字 5 与字符串 "5" 是相同的。

技术细节

返回值: 返回包含数组中所有键名的一个新数组。
PHP 版本: 4+
更新日志: strict 参数是在 PHP 5.0 中新增的。

更多实例

实例 1

使用 value 参数:

<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a,"Highlander"));
?>

实例 2

使用 strict 参数 (false):

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

实例 3

使用 strict 参数 (true):

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

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

Design and Analysis of Distributed Algorithms (Wiley Series on P

Design and Analysis of Distributed Algorithms (Wiley Series on P

Nicola Santoro / Wiley-Interscience / 2006-10-27 / USD 140.95

This text is based on a simple and fully reactive computational model that allows for intuitive comprehension and logical designs. The principles and techniques presented can be applied to any distrib......一起来看看 《Design and Analysis of Distributed Algorithms (Wiley Series on P》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具