PHP Unset Array value effect on other indexes

后端 未结 6 1192
春和景丽
春和景丽 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 00:49

    This might be a little bit out of context but in unsetting values from a global array, apply the answer by Michael Berkowski above but in use with $GLOBALS instead of the the global value you declared with global $variable_name. So it will be something like:

    unset($GLOBALS['variable_name']['array_key']);

    Instead of:

    global $variable_name; unset($variable_name['array_key']);

    NB: This works only if you're using global variables.

提交回复
热议问题