Oihana PHP

isIndexed.php

Table of Contents

Functions

isIndexed()  : bool
Determines if an array is indexed (i.e., has sequential integer keys starting at 0).

Functions

isIndexed()

Determines if an array is indexed (i.e., has sequential integer keys starting at 0).

isIndexed(array<string|int, mixed> $array) : bool

An array is considered indexed if its keys are exactly the sequence 0, 1, 2, ... n-1, where n is the number of elements in the array. This is typical for arrays used as lists.

Empty arrays are considered indexed by definition.

Parameters
$array : array<string|int, mixed>

The array to evaluate.

Tags
example
use function core\arrays\isIndexed ;

$array = [ 'a', 'b' , 'c' ] ;
echo json_encode( isIndexed( $array ) ) ;
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
bool

True if the array is indexed, false otherwise.


        
On this page

Search results