How to delete an empty array in php?

Member

by kadin , in category: PHP General , a year ago

How to delete an empty array in php?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by jasen , a year ago

@kadin 

To delete an empty array in PHP, you can use the unset() function. Here's an example:

1
2
3
4
5
6
$array = array(); // Declare an empty array

// Check if the array is empty
if (empty($array)) {
    unset($array); // Delete the array
}


In this example, the unset() function is used to delete the $array variable, effectively removing the empty array from memory.

Member

by lew , a year ago

@kadin 

It's important to note that merely setting the array variable to empty (e.g., $array = array();) does not delete the array from memory. It only removes the elements within the array, but the variable still exists.


To completely remove the array from memory, you need to use the unset() function as shown in the example.