Re: array/iteration issue!!

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

 



On Thu, 2008-11-27 at 22:22 -0600, Micah Gersten wrote:
>
> This is actually a much smaller data structure.
> 
> $colleges = array
> (
>  	'Blah Blah University' =>
>         array
>         (
>             'physics' => array
>                 (
>                     'sss',
>                     'sffgg',
>                 ),
>             'english' => array
>                 (
>                     'sss',
>                     'sffgg',
>                 )
> 	),
> 	'Glah Gleh University' =>
>         array
>         (
>             'physics' => array
>                 (
>                     'sss',
>                     'sffgg',
>                 ),
>             'english' => array
>                 (
>                     'sss',
>                     'sffgg',
>                 ),
>         )
>  );
> 
> 
> foreach( $colleges as $collegeName => $depts )
> {
>      foreach( $depts as $deptName => $classes)
>     {
>         foreach( $classes as $className )
>         {
>             echo "$collegeName, $deptName, $className\n";
>         }
>     }
> }

Yes, I thought of that one too, but it's less flexible. What if you need
to add other fields to the college, or department. Then you'd need to
redo the whole structure to something more similar to what I did. Since
bruce was having issues, I gave him a flexible format that could handle
other fields if they arose.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux