[thelist] PHP - Parsing Arrays

Burhan Khalid thelist at meidomus.com
Thu Oct 9 17:00:01 CDT 2003


Alex Ezell wrote:

> PHP Code:
> 
> Array ( 
> [0] => Array ( 
>   [workID] => 7 
>   [workFileName] => dentalWhiteOnBlue2.jpg 
>   [workFileSize] => 87072 
>   [projectID] => 4 
>   [workDescription] => Main photography for the interior wall splash. 
>   [workTypeName] => Brand Awareness 
>   [projectName] => Neocon Booth 
>   [clientID] => 2 
>   [projectDescription] => Design and specify vendor for booth at Neocon trade show. 
>   [projectTypeName] => Electronic Marketing 
>   [clientEngageDate] => 2001-10-17 
>   [clientDescription] => Patcraft manufactures commercial carpet for a variety of applications including heavy industrial. 
>   [clientName] => Patcraft 
>   [clientCity] => Dalton 
>   [clientState] => GA 
>   [clientTypeName] => Commercial Flooring - Manufacturer 
> ) 

[ snipped rest of code ]

> Each uppermost item in the Array is a "work." These works are collected into saved configurations which are just groups of works as chosen by the user. The entire array then represents the "works" that the user wants to include in their final product, which is a static HTML portfolio.
> 
> What I need to extract into other arrays are the distinct client data, distinct project data by client, distinct work data by project. I'm not even sure if I want to end up with an array that is resorted or several different arrays or what. 

What I would do is modify your array so it is a multi-dimentional array. 
This would make it easier to split out the individual "sections".

Example array would be :

  Array
(
     [0] => Array
         (
             [work] => Array
                 (
                     [workID] => 7
                     [workFileName] => dental
                     [workFileSize] => 87072
                     [workTypeName] => Brand
                 )

             [project] => Array
                 (
                     [projectID] => 4
                     [projectName] => Neocon
                     [projectDescription] => foo bar
                 )

             [client] => Array
                 (
                     [clientName] => Patcraft
                     [clientCity] => Dalton
                     [clientState] => GA
                 )

         )

)

Another option would be to use something like PEAR::Config which can 
spit out configuration information (kinda like your situation) in 
various formats.

If I can think of anything else, I'll post :)


-- 
Burhan Khalid
thelist[at]meidomus[dot]com
http://www.meidomus.com



More information about the thelist mailing list