Home  >  Article  >  Backend Development  >  PHP8.1 new features explained array_is_list function

PHP8.1 new features explained array_is_list function

藏色散人
藏色散人Original
2021-11-10 15:37:143366browse

This article is a translation, original address: https://stitcher.io/blog/new-in-php-81#new-array_is_list-function-rfc

PHP8.1 new features explained array_is_list function

New array_is_list feature

You may occasionally have to deal with this problem: determining whether the keys of an array are in numerical order, starting at index 0. Just like json_encode determines whether an array should be encoded as an array or an object.

PHP 8.1 added a built-in function to determine if an array is a list with these semantics:

$list = ["a", "b", "c"];
array_is_list($list); // true
$notAList = [1 => "a", 2 => "b", 3 => "c"];
array_is_list($notAList); // false
$alsoNotAList = ["a" => "a", "b" => "b", "c" => "c"];
array_is_list($alsoNotAList); // false

See RFC for details: https://wiki.php.net/rfc/ is_list

The above is the detailed content of PHP8.1 new features explained array_is_list function. For more information, please follow other related articles on 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