3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $value = 2; $array = [1, 2, 3]; array_unshift($array,$value); // prepend a duplicate var_export(array_unique($array)); // kill the original echo "\n---\n"; $value = 2; $array = [1, 2, 3]; var_export(array_unique(array_merge([$value],$array))); // prepend a duplicate, kill the original echo "\n---\n"; $value = 2; $array = [1, 2, 3]; array_unshift($array,$value); // prepend a duplicate var_export(array_keys(array_keys($array))); // kill the original echo "\n---\n"; $value = 2; $array = [1, 2, 3]; var_export(array_keys(array_keys(array_merge([$value],$array)))); // prepend a duplicate, kill the original
based on krc2G
Output for 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.30 - 7.3.0alpha1
array ( 0 => 2, 1 => 1, 3 => 3, ) --- array ( 0 => 2, 1 => 1, 3 => 3, ) --- array ( 0 => 0, 1 => 1, 2 => 2, 3 => 3, ) --- array ( 0 => 0, 1 => 1, 2 => 2, 3 => 3, )