Re: array/iteration issue!!
| From: | Robert Cummings | Date: | Fri, 28 Nov 2008 04:39:36 +0000 |
| Subject: | Re: array/iteration issue!! | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-283883@lists.php.net to get a copy of this message | ||
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