array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.array-is-list.php', 1 => 'array_is_list', ), 'up' => array ( 0 => 'ref.array.php', 1 => '数组 函数', ), 'prev' => array ( 0 => 'function.array-intersect.php', 1 => 'array_intersect', ), 'next' => array ( 0 => 'function.array-key-exists.php', 1 => 'array_key_exists', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/array/functions/array-is-list.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 8 >= 8.1.0)
array_is_list — 判断给定的 array
是否为 list
判断指定的 array
是否是 list。如果 array 的 key 由 0
到 count($array)-1
的连续数字组成,则该数组就是 list。
示例 #1 array_is_list() 示例
<?php
array_is_list([]); // true
array_is_list(['apple', 2, 3]); // true
array_is_list([0 => 'apple', 'orange']); // true
// key 未从 0 开始
array_is_list([1 => 'apple', 'orange']); // false
// key 的顺序不正确
array_is_list([1 => 'apple', 0 => 'orange']); // false
// 包含非整数 key
array_is_list([0 => 'apple', 'foo' => 'bar']); // false
// 非连续 key
array_is_list([0 => 'apple', 2 => 'bar']); // false
?>
注意:
空数组也会返回
true
。