array help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

array help

Post 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
phpice
Forum Newbie
Posts: 4
Joined: Sun Feb 04, 2007 1:57 pm

Post 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.
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Post by ddragas »

thank you for reply

regards ddragas
Post Reply