array_is_list(array $array): bool
The function returns true if the array is a list and false otherwise.
$array = [10, 20, 30];
$result = array_is_list($array);
echo $result ? 'True' : 'False';
True
$array = ['a' => 1, 'b' => 2];
$result = array_is_list($array);
echo $result ? 'True' : 'False';
False
$array = [0 => 'apple', 'x' => 'banana', 1 => 'orange'];
$result = array_is_list($array);
echo $result ? 'True' : 'False';
False
$array = [];
$result = array_is_list($array);
echo $result ? 'True' : 'False';
True
$array = [0 => 'apple', 2 => 'banana', 3 => 'orange'];
$result = array_is_list($array);
echo $result ? 'True' : 'False';
False
$array = [1=>'Green',2=>'Red',3=>'Blue']; // Not starting with 0
$result = array_is_list($array);
echo $result ? 'True' : 'False';
False
$array = [-1=>'Green',0=>'Red',1=>'Blue']; // Not starting from 0
$result = array_is_list($array);
echo $result ? 'True' : 'False';
False
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.