3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = array( 'empty array' => array(), 'consecutive from 0' => array( 0 => 'one', 1 => 'two', ), 'consecutive from 0 float' => array( 0.0 => 'one', 1.0 => 'two', ), 'consecutive from 0 str' => array( '0' => 'one', '1' => 'two', ), 'consecutive from 1' => array( 1 => 'one', 2 => 'two', ), 'consecutive from 1 float' => array( 1.0 => 'one', 2.0 => 'two', ), 'consecutive from 1 str' => array( '1' => 'one', '2' => 'two', ), 'non-consecutive int' => array( 1 => 'one', 0 => 'two', ), 'non-consecutive float' => array( 1.0 => 'one', 0.0 => 'two', ), 'non-consecutive string' => array( '1' => 'one', '0' => 'two', ), ); foreach ( $tests as $test => $arr ) { echo str_pad( $test, 30 ), var_export( array_is_list( $arr ), true ), PHP_EOL; }
Output for 8.1.2 - 8.1.27, 8.2.10 - 8.2.16, 8.3.0 - 8.3.3
empty array true consecutive from 0 true consecutive from 0 float true consecutive from 0 str true consecutive from 1 false consecutive from 1 float false consecutive from 1 str false non-consecutive int false non-consecutive float false non-consecutive string false

preferences:
62.91 ms | 403 KiB | 22 Q