PHP Unset Array value effect on other indexes PHP Unset Array value effect on other indexes arrays arrays

PHP Unset Array value effect on other indexes


The keys are not shuffled or renumbered. The unset() key is simply removed and the others remain.

$a = array(1,2,3,4,5);unset($a[2]);print_r($a);Array(    [0] => 1    [1] => 2    [3] => 4    [4] => 5)


Test it yourself, but here's the output.

php -r '$a=array("a","b","c"); print_r($a); unset($a[1]); print_r($a);'Array(    [0] => a    [1] => b    [2] => c)Array(    [0] => a    [2] => c)


They are as they were. That one key is JUST DELETED