Jump to content

removing empty elements from the end of an array


johnny5

Recommended Posts

hi

i know this method is a pain in the... but heres what i do to get rid of all empty elements

firstly when i create the array, i create the first element as empty, so if its in an explode for example i would say

$myarray = explode("\n", "\n" . $mystring);

... and then array_unique to remove duplicates of empties

$myarray = array_unique($myarray);

... and then slice of the first elemnt

$myarray = array_slice($myarray,1);

This only works is you know that all the elements of the array are going to be unique, so it might not be best for you...

hope its helpful

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.