HomeLanguagesPHP array_is_list() Function

PHP array_is_list() Function

The array_is_list() function is an inbuilt function in PHP that is used to check whether a given array is a list or not. If the given array will be a list if the key of the array contains consecutive numbers from 0 to count($arr)-1.

Syntax: 

bool array_is_list(array $array)

Parameters: This function accepts one parameter $array that will check for the list.

Return Value: This function returns true if the given array is a list and false otherwise.

Note: This function returns true on an empty array.

Example 1:

PHP




<?php
  
$arr1 = array("10", "20", "30", "40", "50");
  
var_dump(array_is_list($arr1));
  
$arr2 = array(
    'Geeks'  => "HTML", 
    'GFG'  => "CSS", 
    'Geek'  => "JavaScript", 
    'G4G' => "PHP"
);
  
var_dump(array_is_list($arr2));
  
?>


Output:

bool(true)
bool(false)

Example 2:

PHP




<?php
  
var_dump(array_is_list([]));
  
var_dump(array_is_list(array(
    "10" => "Geeks", 
    "20" => "neveropen",
    "30", 
    "40", 
    "50"
)));
  
var_dump(array_is_list(
    array(5, 10, 15, 20, 25)
));
  
?>


Output:

bool(true)
bool(false)
bool(true)

Note: This function works on PHP 8.1.0 or higher versions.

Reference: https://www.php.net/manual/en/function.array-is-list.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS