Remove empty array elements
Asked 07 September, 2021
Viewed 774 times
  • 52
Votes

Some elements in my array are empty strings based on what the user has submitted. I need to remove those elements. I have this:

foreach($linksArray as $link)
{
    if($link == '')
    {
        unset($link);
    }
}
print_r($linksArray);

But it doesn't work. $linksArray still has empty elements. I have also tried doing it with the empty() function, but the outcome is the same.

27 Answer