PHP Programming: Warning: PHP Arrays are undefined or uncleared until you reset them.

Updated 2018-09-26

Beware! This is a subtle problem that can have serious consequences for the operation of your PHP code. If you do not explicitly assign at least one value to a new array (or an array that you are going to use anew in loop, say) or set it to be empty, then it will either have undefined contents (or it will contain values that were previously assigned to it in a previous loop).

If you have any doubt that you are immediately going to assign defined values to the array (or even if you don’t), you must specifically clear the array like this:

$my_undefined_array = array();
Published 2018-09-26
Category: Web programming
Tags: ,