removing empty elements from the end of an array
Posted 28 September 2006 - 11:42 PM
I'm saving the array as a serialized TEXT in mysql and just want to drop redundent empty cells at the end.
Posted 29 September 2006 - 09:24 AM
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
Posted 29 September 2006 - 09:33 AM
Can anybody tell me how to remove just the empty elements on the end of array.
Maybe you should be looking at why you have empty elements at the end of an array in the first place
Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools
Posted 29 September 2006 - 09:43 AM
$old_array = array ( '', 'happy', 'sad', 'mad', '' ); $new_array = array_diff ( $old_array, array ( '' ) ); print_r ( $new_array );
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users