...

View Full Version : traversing multi-array of objects in PHP4



kktaus
02-17-2006, 06:03 PM
I am working on traversing a multi-dimentsional array in order to print out items with html formatting. So far this code only works on one dimension. Here is the array:


Array
(
[0] => xml Object
(
[tag] => teleconferences
[value] =>
[attributes] =>
[next] => Array
(
[0] => xml Object
(
[tag] => series
[value] => Library Teleconference Series
[attributes] =>
[next] => Array
(
[0] => xml Object
(
[tag] => title
[value] => Library Stuff
[attributes] =>
[next] => Array
(
[0] => xml Object
(
[tag] => date
[value] => February 3, 2006
[attributes] =>
[next] =>
)

)

)

[1] => xml Object
(
[tag] => title
[value] => More Library Stuff
[attributes] =>
[next] => Array
(
[0] => xml Object
(
[tag] => date
[value] => April 7, 2006
[attributes] =>
[next] =>
)

)

)

)

)


The PHP looks like:



function test_array_walk_recurs( $item, $key ) {
if( is_object($item) && array_key_exists('value', $item) ) {
foreach ($item as $key=>$value) {
//do html stuff here
print $value;
}
}
if(is_array($item) ) {
array_walk($item, 'test_array_walk_recurs');
}
}


array_walk($Xml, 'test_array_walk_recurs');



Anyone see the error in my ways?

goughy000
02-17-2006, 06:17 PM
put your code in PHP forum tags, it might help point out the error

EDIT: thanx



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum