How to clear an array in PHP
In this tutorial, we are going to learn about how to clear or empty an array of values in PHP.
Clearing the array
To clear an array in PHP, we need to reintialize the variable with an empty array.
Here is an example, that removes the all values from a $users
array:
$users = array("john", "nancy", "salsa");
$users = array(); #clears all elements
echo $users;