Jump to content

Extract Nested Array from Main Array


MrRundog

Recommended Posts

Hi Folks - Fro this multi array I need to extract the [Vehicle] array info or ineed the whole [vehicle] array itself - Would someone know the correct loop or extraction method please?

Array
(
    [] => Array
        (
            [release] => 8.1
            [environment] => Production
            [lang] => en-US
            [xmlns] =>
            [ApplicationArea] => Array
                (
                    [sender] => Array
                        (
                            [LogicalId] => 0
                            [Component] => CarweBVRRWebService
                            [Task] => strB2BGetVehicleByVRM
                        )

                    [CreationDateTime] => 2008-06-25T13.52.52Z
                    [bODId] =>
                    [Destination] => Array
                        (
                            [DestinationNameCode] => 1

                        )

                )

            [DataArea] => Array
                (
                    [Error] => Array
                        (
                            [Header] => Array
                                (
                                    [DocumentDateTime] => 2008-06-25T13.52.52Z
                                )

                        )

                    [Vehicles] => Array
                        (
                            [Vehicle] => Array
                                (
                                    [bodyStyle] =>  4 DOOR SALOON
                                    [CO2] => 151
                                    [DateFirstRegistered] => 2001-12-03

                                )

                        )

                )

        )

)


 

Cheers

MR

Link to comment
https://forums.phpfreaks.com/topic/112177-extract-nested-array-from-main-array/
Share on other sites

MrRundog,

 

It worked for me when I assigned the Second Level array a Key value a value of zero.

 

Scot L. Diddle, Richmond VA

 


<?php 

$data = Array
(
    0 => Array
        (
            'release' => 8.1,
            'environment' => Production,
            'lang' => en-US,
            'xmlns' => NULL,
            'ApplicationArea' => Array
                (
                    'Sender' => Array
                        (
                            'LogicalId' => 0,
                            'Component' => CarweBVRRWebService,
                            'Task' => strB2BGetVehicleByVRM,
                        ),

                    'CreationDateTime' => '2008-06-25T13.52.52Z',
                    'BODId' => NULL,
                    'Destination' => Array 
                        (
                            'DestinationNameCode' => 1,

                        )

                ),

            'DataArea' => Array
                (
                    'Error' => Array
                        (
                            'Header' => Array
                                (
                                    'DocumentDateTime' => '2008-06-25T13.52.52Z'
                                )

                        ),

                    'Vehicles' => Array
                        (
                            'Vehicle' => Array
                                (
                                    'BodyStyle' =>  '4 DOOR SALOON',
                                    'CO2' => 151,
                                    'DateFirstRegistered' => '2001-12-03',

                                )

                        ),

                ),

        ),

);



$vehicle_array = $data[0]['DataArea']['Vehicles']['Vehicle'];

print_r($vehicle_array) 

?>

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.