Re: removing values from arrays
| From: | Edwin Boersma | Date: | Mon, 09 Jun 2003 08:37:02 +0000 |
| Subject: | Re: removing values from arrays | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-28442@lists.php.net to get a copy of this message | ||
You can also use unset(): if (!array[$key]) unset array[$key].
Edwin
Peter Beckman wrote:
$x=0; while ($row = mysql_fetch_array($r)) {while(list($key,$val)=each($row)) { if (!empty($val)) $mydata[$x][$key] = $val; } $x++} Peter On Wed, 21 May 2003, John wrote:ok I've been racking my brain on this for a couple of days. What I need to do is after creating an array from a query some values are 0. I need to be able to "skip" both the value and the key frmprinting purposes. I have it setup in a multi-demensional array, such as: Array ( [0] => Array---------------------------------------------------------------------------( [Department] => IMAX [Occurrences] => 1 [percentage resets of completed] => 0.00 [completed] => 1 [In Progress] => 0 [Waiting for Parts] => 0 [deferred] => 0 )[1] => Array( [Department] => SSG [Occurrences] => 1 [percentage resets of completed] => [completed] => 0 [In Progress] => 1 [Waiting for Parts] => 0 [deferred] => 0 )[2] => Array( [Department] => Lobby [Occurrences] => 2 [percentage resets of completed] => 0.00 [completed] => 1 [In Progress] => 1 [Waiting for Parts] => 0 [deferred] => 0 )[3] => Array( [Department] => BTGallery [Occurrences] => 10 [percentage resets of completed] => 44.44 [completed] => 9 [In Progress] => 1 [Waiting for Parts] => 0 [deferred] => 0 )[4] => Array( [Department] => Temp [Occurrences] => 15 [percentage resets of completed] => 53.85 [completed] => 13 [In Progress] => 2 [Waiting for Parts] => 0 [deferred] => 0 )[5] => Array( [Department] => KidZone [Occurrences] => 16 [percentage resets of completed] => 0.00 [completed] => 11 [In Progress] => 5 [Waiting for Parts] => 0 [deferred] => 0 )[6] => Array( [Department] => WWC [Occurrences] => 16 [percentage resets of completed] => 35.71 [completed] => 14 [In Progress] => 1 [Waiting for Parts] => 1 [deferred] => 0 )[7] => Array( [Department] => BodyWatch [Occurrences] => 38 [percentage resets of completed] => 51.72 [completed] => 29 [In Progress] => 8 [Waiting for Parts] => 1 [deferred] => 0 )[8] => Array( [Department] => TimeZone [Occurrences] => 70 [percentage resets of completed] => 66.67 [completed] => 60 [In Progress] => 9 [Waiting for Parts] => 0 [deferred] => 1 )[9] => Array( [Occurrences] => 169 [percentage resets of completed] => 51.45 [Completed] => 138 [In Progress] => 28 [Waiting for Parts] => 2 [Deferred] => 1 )) what I want it as is : Array ( [0] => Array( [Department] => IMAX [Occurrences] => 1 [completed] => 1 )[1] => Array( [Department] => SSG [Occurrences] => 1 [In Progress] => 1 )[2] => Array( [Department] => Lobby [Occurrences] => 2 [completed] => 1 [In Progress] => 1 )[3] => Array( [Department] => BTGallery [Occurrences] => 10 [percentage resets of completed] => 44.44 [completed] => 9 [In Progress] => 1 )[4] => Array( [Department] => Temp [Occurrences] => 15 [percentage resets of completed] => 53.85 [completed] => 13 [In Progress] => 2 )[5] => Array( [Department] => KidZone [Occurrences] => 16 [completed] => 11 [In Progress] => 5 )[6] => Array( [Department] => WWC [Occurrences] => 16 [percentage resets of completed] => 35.71 [completed] => 14 [In Progress] => 1 [Waiting for Parts] => 1 )[7] => Array( [Department] => BodyWatch [Occurrences] => 38 [percentage resets of completed] => 51.72 [completed] => 29 [In Progress] => 8 [Waiting for Parts] => 1 )[8] => Array( [Department] => TimeZone [Occurrences] => 70 [percentage resets of completed] => 66.67 [completed] => 60 [In Progress] => 9 [deferred] => 1 )[9] => Array( [Occurrences] => 169 [percentage resets of completed] => 51.45 [Completed] => 138 [In Progress] => 28 [Waiting for Parts] => 2 [Deferred] => 1 )) Basically just remove the keys and values where the value is 0 or not set; any ideas would be appreciated. John Coder -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpPeter Beckman Internet Guy beckman@purplecow.com http://www.purplecow.com/---------------------------------------------------------------------------