Below, you can find several ways to add elements to an array, depending on your exact needs. which is the best way to check that an array is empty. We can also delete an array element by using the PHP unset feature. This question on 'How to tell if a PHP array is empty' had me thinking of this question Is there a reason that count should be used instead of empty when determining if an array is empty or not?. Q&A for work. Why date is required field in form? furthermore, both function in PHP counts the number of elements of an array or a countable object. A. 2. The array to iterate over callback. My personal thought would be if the 2 are equivalent for the case of empty arrays you should use empty because it gives a boolean answer to a boolean question. Flag determining what arguments are sent to callback: . The callback function to use If no callback is supplied, all empty entries of array will be removed. Use count() Function to Check Whether an Array Is Empty in PHP. An array in PHP is actually an ordered map. An array can be checked to see if it is empty or not in multiple ways. Learn more Unset an element of an array with its index. Definition and Usage. Note that this will overwrite an existing array value of the same path. Add Elements to an Empty Array¶ After creating an empty array, you can get to adding elements to it. Arrays. 2. Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share … See empty() for how PHP defines empty in this case.. mode. Teams. 0.