3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = ['4', 'x' => 5]; // construct with duplicate keys var_dump(['x' => 4, 'x' => 6]); var_dump([2 => 4, 2.0 => 6]); // spread operator leading to duplicate keys var_dump(['x' => 4, ...$arr]); // destruct with duplicate keys ['x' => $a, 'x' => $b] = ['x' => 10]; var_dump([$a, $b]);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(1) { ["x"]=> int(6) } array(1) { [2]=> int(6) } array(2) { ["x"]=> int(5) [0]=> string(1) "4" } array(2) { [0]=> int(10) [1]=> int(10) }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30
array(1) { ["x"]=> int(6) } array(1) { [2]=> int(6) } Fatal error: Uncaught Error: Cannot unpack array with string keys in /in/NTFPM:10 Stack trace: #0 {main} thrown in /in/NTFPM on line 10
Process exited with code 255.

preferences:
115 ms | 402 KiB | 121 Q