Re: "Trim" an array?

From: Date: Fri, 02 Feb 2001 22:34:56 +0000
Subject: Re: "Trim" an array?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-37913@lists.php.net to get a copy of this message
On Fri, 02 Feb 2001 17:31:43 -0500, Thomas Deliduka (thomas@neweve.com) wrote: >I looked through the archives and couldn't find anything on this. > >I have a web form which takes 9 values to create a definition for a >table >that would have up to 9 columns. > >I made the table so that each form field is submitted as an array so >that I >can simply step through each value and create the table definition, >so: > ><input type=text name="tblcol[]"> (duplicated 9 times) > >Now, when I submit the form the resulting array always has 9 >elements and >some of those will be empty. > >I would like to do error checking in case people didn't fill >anything at all >so I thought using if (!count($tblcol)) {.... But that doesn't work >since it >always has 9 elements. > >Is there a way to find out if an array contains no values even >though it has >elements? Sort of like a trim() function on an array to destroy the >elements in the array that are empty. > >Is it possible? while(list($key,$value)=each($array)){ if(empty($value)) unset $array[$key]; }

« previous php.general (#37913) next »