Jump to content

Recommended Posts

hi there,

this is a kind of array i get after i have parsed my xml.

now i wanted to extract data from this array:

name and cdata elements needs to be extracted.any ideas?

[2] => Array
        (
            [name] => DELIVERY
            [attrs] => Array
                (
                )

            [children] => Array
                (
                    [0] => Array
                        (
                            [name] => PACKAGEREFERENCENUMBER
                            [attrs] => Array
                                (
                                )

                            [children] => Array
                                (
                                    [0] => Array
                                        (
                                            [name] => CODE
                                            [attrs] => Array
                                                (
                                                )

                                            [cdata] => IK
                                        )

                                    [1] => Array
                                        (
                                            [name] => VALUE
                                            [attrs] => Array
                                                (
                                                )

                                            [cdata] => 66759
                                        )

                                )

                        )

Link to comment
https://forums.phpfreaks.com/topic/63604-solved-extracting-array-elements/
Share on other sites

<?php
$data = array (
    '2' => Array
        (
            'name' => 'DELIVERY',
            'attrs' => Array
                (
                ),

            'children' => Array
                (
                    '0' => Array
                        (
                            'name' => 'PACKAGEREFERENCENUMBER',
                            'attrs' => Array
                                (
                                ),

                            'children' => Array
                                (
                                    '0' => Array
                                        (
                                            'name' => 'CODE',
                                            'attrs' => Array
                                                (
                                                ),

                                            'cdata' => IK
                                        ),

                                    '1' => Array
                                        (
                                            'name' => 'VALUE',
                                            'attrs' => Array
                                                (
                                                ),

                                            'cdata' => 66759
                                        )

                                )

                        )
                   )
            )
  );
  
foreach ($data[2]['children'][0]['children'] as $childArray)
{
    echo 'Name : ', $childArray['name'], '<br>';
    echo 'CData : ', $childArray['cdata'], '<br><br>'; 
} 
?>

hi thanks for he solution.i have one question on that though...

how do i convert my array to the modifications you have done to my array.

like u added "data=

and 'children','0'..?

 

that is the array  when i convert xml into array?

any idea abt how i can get this array matched with the array you have shown in your solution?>

 

Thanks again !

 

I added $data because I had to call it something. I have no way of knowing what you called it, and as it was an extract, starting at element 2, I have no way of knowing the full structure of your array.

 

The "children" and "0" etc are the keys in your array, not added by me.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.