Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    traversing multi-array of objects in PHP4

    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:
    Code:
    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:

    PHP Code:
    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?
    Last edited by kktaus; 02-17-2006 at 06:48 PM.

  • #2
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    put your code in PHP forum tags, it might help point out the error

    EDIT: thanx
    Last edited by goughy000; 02-18-2006 at 12:38 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •