On Thu, 2008-11-27 at 18:55 -0800, bruce wrote:
> hey robert..
>
> ok.. so if i changed the array to have a dept1, and a dept2
>
> $a=array("college"=> "foo",
> "dept1"=>array("dept"=> "physics",
> "class"=>array("class1"=>"sss","class2"=>"sffgg")
> ),
> "dept2"=>array("dept"=> "english",
> "class"=>array("class1"=>"sss","class2"=>"sffgg")
> )
> );
> how would i iterate through this..??
Your array is terribly structured. But the following provides traversal
in the way you want:
<?php
$a = array
(
"college" => "foo",
"dept1" => array
(
"dept" => "physics",
"class" => array
(
"class1" => "sss",
"class2" => "sffgg"
)
),
"dept2" => array
(
"dept" => "english",
"class" => array
(
"class1" => "sss",
"class2" => "sffgg"
)
)
);
$college = $a['college'];
foreach( $a as $deptKey => $deptInfo )
{
if( strpos( $deptKey, 'dept' ) === 0 )
{
$dept = $deptInfo['dept'];
foreach( $deptInfo['class'] as $class )
{
echo "$college, $dept, $class\n";
}
}
}
?>
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