RE: removing values from arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: John [mailto:mrpeabodi@insightbb.com]
> Sent: 21 May 2003 23:19
> 
> 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
>         )

> what I want it as is :
> 
> Array
> (
>     [0] => Array
>         (
>             [Department] => IMAX
>             [Occurrences] => 1
>             [completed] => 1
>         )

Try something like:

   foreach ($array as $key=>$subarray):
      foreach ($subarray as $subkey=>$subval):
         if (empty($subval)):
            unset($array[$key][$subkey]);
         endif;
      endforeach;
   endforeach;

(untested, so caveat programmor!)

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux