PHP array_is_list function

Last Updated: February 13, 2022

array_is_list — Checks whether a given array is a list

Syntax

array_is_list(array $array): bool

Supports (PHP 8 >= 8.1.0)

Parameters

array – the array you want to evaluate

Return Value

The return value is a boolean value

Example


<?php

array_is_list([]); // true
array_is_list(['orange', 2, 3]); // true
array_is_list([0 => 'orange', 'apple']); // true

// The array does not start at 0
array_is_list([1 => 'apple', 'orange']); // false

// The keys are not in the correct order
array_is_list([1 => 'apple', 0 => 'orange']); // false

// Non-integer keys
array_is_list([0 => 'apple', 'foo' => 'bar']); // false

// Non-consecutive keys
array_is_list([0 => 'apple', 2 => 'bar']); // false
?>

Test