How to delete an empty array in php?

Member

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

How to delete an empty array in php?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by samara , a year ago

@brandy 

In PHP, you cannot delete an empty array directly because it does not occupy any memory space. However, you can assign a new value to the variable holding the array to remove the reference to the empty array. Here's an example:

1
2
3
4
5
6
7
8
9
$array = []; // empty array

// unset the variable to remove the reference to the empty array
unset($array);

// Alternatively, you can assign a new value to the variable
$array = null;

// Now, the empty array is no longer accessible


Both unset($array) and $array = null will achieve the desired result of removing the empty array.

Related Threads:

How to delete an empty array in php?
How to delete an empty array in php?
How to store an empty array in redis?
How to check if an associative array is empty in powershell?
How to check if a variable is empty in PHP?
How to declare an empty variable inside function in php?