Jump to content

[SOLVED] extract info from a multi array


ballhogjoni

Recommended Posts

How would I extract ID and transactionID from the last array in this example? The multi array comes from a $result variable from a thrid party xml file or database. The code is:

 

$result = $client->send($msg,'http://xxxxxxxxxxxxxxxxxxxxxxxxxx);

 

Array
(
    [getthisinfo] => Array
        (
            [Cards] => Array
                (
                    [Card] => Array
                        (
                            [0] => Array
                                (
                                    [iD] => 12
                                    [TransactionID] => 100228873
                                )
                        )
               )
      )
)

 

This is the code I have and it only gets the info from the first array.

 

foreach($result as $key=>$val){
echo '<tr><td>'.$key.'</td><td>'.$val.'</td></tr>';
}

Link to comment
Share on other sites

Thx, let me take it one step further and ask; How would I plug that into a foreach loop and print all the data? You said "$result['getthisinfo']['cards']['card'][0]['ID']

$result['getthisinfo']['cards']['card'][0]['TransactionID']" which makes sense for the \[0] index, but what if I had 10 or 20 indexes?

Link to comment
Share on other sites

// example 1:
foreach($result['getthisinfo']['cards']['card'] as $list) {
   echo "ID: {$list['ID']} TransactionID: {$list['TransactionID']} <br />";
}

// example 2:
foreach($result['getthisinfo']['cards']['card'] as $list) {
   foreach ($list as $key => $val) {
      echo "$key : $val ";
   }
   echo "<br />";
}

 

Link to comment
Share on other sites

when I try your example one I get an error:

Warning:  Invalid argument supplied for foreach() in /home/xxxxxxxx/public_html/xxxxxxxxx/api/xxxxxxxxxxx.php on line 63

 

What would this be? Line 63 is foreach($result['getthisinfo']['cards']['card'] as $list) {

Link to comment
Share on other sites

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.