Page 1 of 1

array help

Posted: Sun Feb 04, 2007 1:38 pm
by ddragas
hi all

Help needed to get values ftom an array

this is array

Code: Select all

Array
(
    [0] => Array
        (
            [name] => DELIVERYREPORT
            [content] => 
	
	
	
            [child] => Array
                (
                    [0] => Array
                        (
                            [name] => MESSAGE
                            [attrs] => Array
                                (
                                    [ID] => 1023012301
                                    [SENTDATE] => 
                                    [DONEDATE] => 2005/7/19 22:0:0
                                    [STATUS] => NOT_SENT
                                )

                        )

                    [1] => Array
                        (
                            [name] => MESSAGE
                            [attrs] => Array
                                (
                                    [ID] => 1023012302
                                    [SENTDATE] => 
                                    [DONEDATE] => 2005/7/19 22:0:2
                                    [STATUS] => NOT_SENT
                                )

                        )

                    [2] => Array
                        (
                            [name] => MESSAGE
                            [attrs] => Array
                                (
                                    [ID] => 1023012303
                                    [SENTDATE] => 
                                    [DONEDATE] => 2005/7/19 22:0:3
                                    [STATUS] => NOT_SENT
                                )

                        )

                )

        )

)

i need to put this values into variables

[ID] => 1023012301
[SENTDATE] =>
[DONEDATE] => 2005/7/19 22:0:0
[STATUS] => NOT_SENT

Posted: Sun Feb 04, 2007 2:05 pm
by phpice
Assuming the array with the values is called $myarray, then you can do the following:

$id = $myarray[0]['child'][0]['attrs']['ID'];
$sentdate = $myarray[0]['child'][0]['attrs']['SENTDATE'];
$donedate = $myarray[0]['child'][0]['attrs']['DONEDATE'];
$status = $myarray[0]['child'][0]['attrs']['STATUS'];

Or, if you just want to put that whole result into an array, you could do the following:

$result = $myarray[0]['child'][0]['attrs'];

Then, you could access each variable like so:

$id = $result['ID'];
$sentdate = $result['SENTDATE'];
$donedate = $result['DONEDATE'];
$status = $result['STATUS'];

Enjoy.

Posted: Sun Feb 04, 2007 2:27 pm
by ddragas
thank you for reply

regards ddragas