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 9244567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:04:03+00:00 2026-06-18T09:04:03+00:00

For a structure such as SimpleXMLElement Object ( [id] => https://itunes.apple.com/us/rss/topfreeapplications/limit=2/genre=6014/xml [title] => iTunes

  • 0

For a structure such as

SimpleXMLElement Object
(
    [id] => https://itunes.apple.com/us/rss/topfreeapplications/limit=2/genre=6014/xml
    [title] => iTunes Store: Top Free Applications in Games
    [updated] => 2013-02-04T07:18:54-07:00    
    [icon] => http://itunes.apple.com/favicon.ico
    [entry] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [updated] => 2013-02-04T07:18:54-07:00
                    [id] => https://itunes.apple.com/us/app/whats-word-new-quiz-pics-words/id573511269?mt=8&uo=2
                    [title] => What is the Word? - new quiz with pics and words - RedSpell
                )

            [1] => SimpleXMLElement Object
                (
                    [updated] => 2013-02-04T07:18:54-07:00
                    [id] => https://itunes.apple.com/us/app/temple-run-2/id572395608?mt=8&uo=2
                    [title] => Temple Run 2 - Imangi Studios, LLC
                )
        )

)

I’m using the following code to target the entry node as each entry node stands for a game.

$xml = simplexml_load_file('the path to file');
foreach ($xml->entry as $val)
{                   
   $gameTitle = $val->title;    
   $gameLink = $val->id;
}

WHAT I’M LOOKING FOR

Target the index of the entry node, i.e. 0, 1, 2 and so on; i.e.

[0] => SimpleXMLElement Object // <-- this fella here, capture 0
(
     [updated] => 2013-02-04T07:18:54-07:00
     [id] => https://itunes.apple.com/us/app/whats-word-new-quiz-pics-words/id573511269?mt=8&uo=2
     [title] => What is the Word? - new quiz with pics and words - RedSpell                  
)
[1] => SimpleXMLElement Object // <-- this fella here, capture 1
(
     [updated] => 2013-02-04T07:18:54-07:00
     [id] => https://itunes.apple.com/us/app/temple-run-2/id572395608?mt=8&uo=2
     [title] => Temple Run 2 - Imangi Studios, LLC
)

Whatever I do, I just can’t seem to get the index of the current node.

UPDATE

Just for you people to test it out Code Viper

  • 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-06-18T09:04:05+00:00Added an answer on June 18, 2026 at 9:04 am

    You are looking for a function called iteator_to_array setting the second parameter to false:

    $entries = iterator_to_array($xml->entry, false);
    foreach ($entries as $index => $val)
    {
        $gameTitle = $val->title;
        echo "<p>$gameTitle</p><p>Index = $index</p>";
    
    }
    

    Demo. Actually you do not must use that function you could also just count:

    $index = 0;
    foreach ($xml->entry as $val)
    {
        echo "<p>{$val->title}</p><p>Index = $index</p>";
        $index++;
    }
    

    By default the $key (as in your example code) is the tagname of the XML element. So you can not use it for the index number by default.

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

Sidebar

Related Questions

I have to parse a 1Gb XML file with a structure such as below
I have xml file with such structure: ... <outer> ... <inner/> ... </outer> ...
I have a server application with such structure: There is one object, call him
I have such XML structure which was returned by SharePoint web services. <rs:data ItemCount=4
i have the xml in a structure such as this: <RWFCriteria reportType=ProgramReview> <item id=36
I want a structure such as www.training.com/courses/course/location where course and location change to a
Given a table structure like such: DECLARE @Employees TABLE(EmployeeID INT ,EmployeeDetails XML) INSERT INTO
I have an xml file with a parent child structure such as : <geometry
How do you parse a JSON structure such as this properties: { /base/pinball/pinball_machine_basis/pinball_machines: {
I am trying to declare a private Data Structure such as the Vector in

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.