3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cars = [ [ 'Volvo', 22, 28 ], // index 0 [ 'BMW', 15, 13 ], // index 1 [ 'Land Rover', 3, 8 ], // index 2 [ 'Add Cars', 'X', 'Y' ] // index i ]; $i = count($cars) -1; // get current last set in the array unset($cars[0]); // unset Volvo unset($cars[1]); // unset BMW unset($cars[$i]); // unset index # the only index not unset is 2 (Land Rover) so it should only be left inside the array print_r($cars);
Output for 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
Array ( [2] => Array ( [0] => Land Rover [1] => 3 [2] => 8 ) )

preferences:
166.6 ms | 408 KiB | 5 Q