Jump to content

Complicated PHP array 2 individual variables


stefanh

Recommended Posts

Hi,

  This is my first message here, but I'm sure it won't be my last.  I'm new to php so please bear with me.  Heres my question.  I'm running a script which converts a XML file to a extremely complicated nested array which I just can't seem to fathom,  I would like to convert this to individual variables or a simpler array.

 

Array

(

    [data] => Array

        (

            [item] => Array

                (

                    [0] => Array

                        (

                            [file] => 1.jpg

                            [title] => Title Test 1

                            [description] => Desc Test 1

                        )

 

                    [1] => Array

                        (

                            [file] => 2.jpg

                            [title] => Title Test 2

                            [description] => Desc Test 2

                        )

 

                )

 

        )

 

)

 

What I would like is something like:

 

file[0] = "1.jpg";

title[0] = "Title Test 1";

description[0] = "Desc Test 1";

 

file[1] = "2.jpg";

title[1] = "Title Test 2";

description[1] = "Desc Test 2";

 

Can someone help me understand my array? any help would be extremely appreciated. Thanks -Stefan  :)

 

$file = array();
$title = array();
$description = array();

foreach($array['data']['item'] as $value){ //assuming your array is stored in $array
     $file[] = $value['file'];
     $title[] = $value['title'];
     $description[] = $value['description'];
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.