Home > Article > Backend Development > PHP8.1 new features explained array_is_list function
This article is a translation, original address: https://stitcher.io/blog/new-in-php-81#new-array_is_list-function-rfc
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!