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

PHP8.1 new features explained array_is_list function

藏色散人
Release: 2023-02-17 12:22:01
Original
3472 people have browsed it

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
Copy after login

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!

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