PHP Unset Array value effect on other indexes

后端 未结 6 1165
春和景丽
春和景丽 2020-12-11 00:17

I am working with a PHP loop, and I had one question regarding how unset affects the array keys. This array uses the standard numeric keys assigned by PHP, 0, 1, 2, 3

6条回答
  •  轮回少年
    2020-12-11 01:06

    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
    )
    

提交回复
热议问题