Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6127523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:31:11+00:00 2026-05-23T16:31:11+00:00

I have some xml that looks like this: <?xml version=1.0?> <data> <items> <item><timestamp>2011-07-11T09:01:42Z</timestamp><title><![CDATA[ some

  • 0

I have some xml that looks like this:

<?xml version="1.0"?>
    <data>
<items>
    <item><timestamp>2011-07-11T09:01:42Z</timestamp><title><![CDATA[ some data here ]]></title><link>http://twitter.com/aurl</link></item>
    <item><timestamp>2011-05-11T09:01:42Z</timestamp><title><![CDATA[ some data here ]]></title><link>http://twitter.com/aurlhere</link></item>
</items>

and I’m trying to loop over it and add it to an array:

 foreach($xml->items->item as $e) {
              $feedData['timestamp'] = $e->timestamp;
            $feedData['title'] = $e->title;
            $feedData['link'] = $e->link;
            $feedData['type'] = $e->type;
        }

    print_r($feedData);

The xml is there and if I put an echo in the foreach I get back 10 responses (whcih are how many items I have) but when I print the array out all I get is one line (which is the last entry in the xml doc).

Array ( [timestamp] => SimpleXMLElement Object ( [0] => 2011-07-08T08:05:19Z ) [title] => SimpleXMLElement Object ( ) [link] => SimpleXMLElement Object ( [0] => http://twitter.com.aurl ) [type] => SimpleXMLElement Object ( ) ) 

I suspoect I’m overwriting the array on each loop. But why ? It should be adding to the array. Sorry my php isn’t great…hence what Is suspect is a bit of a stupid question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:31:12+00:00Added an answer on May 23, 2026 at 4:31 pm

    Well, there is only one $feedData array and you are always setting the value for some specific keys, e.g. $feedData['timestamp']. How do you think this should add to the array? Keys are unique, the same key cannot appear twice, so yes, you are just overwriting the values.

    It seems you want an array of arrays:

    $feedData = array();
    
    foreach($xml->items->item as $e) {
        $feedData[] = array(
            'timestamp' => $e->timestamp;
            'title' => $e->title;
            'link' => $e->link;
            'type' => $e->type;
        );
    }
    

    Have a look at the array manual [docs] for more information about arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I have some XML that looks like this: <abc x={></abc> I want to force
I have some xml that looks like this... <tbody> <tr> <td> <h5> <a class=foo
I have some XML that looks something like this: <Root> <Documents> <Document id=1/> </Documents>
Let's say I have some XML like this <channel> <item> <title>This is title 1</title>
I've got a 2-part question... I have some XML that looks like: <trans-unit id=70
Let's say I have a file-system that looks a little something like this: C:\stuff\build.xml
I have a file which is an XML representation of some data that is
Greetings! I have some XML like this: <Root> <AlphaSection> . . . </AlphaSection> <BetaSection>
Greetings! I have some XML like this: <Root> <MainSection> <SomeNode>Some Node Value</SomeNode> <SomeOtherNode>Some Other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.