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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:19:08+00:00 2026-06-10T10:19:08+00:00

Well I been having issues changing an xml back into an array….It would be

  • 0

Well I been having issues changing an xml back into an array….It would be simple if each xml followed the same format but every XML is different with the exception of the <Formula> tag, formulaname and movespeed
ex:

<Formula>
<formulaname>Basic</formulaname>
<movespeed>1</movespeed>
<str>4</str>
<dex>3</dex>
<int>1</int>
<will>2</will>
</Formula>

or

<Formula>
<formulaname>Basic</formulaname>
<movespeed>1</movespeed>
<box>4</box>
<chicken>3</chicken>
<ducks>1</ducks>
<cereal>2</cereal>
</Formula>

What I have tried:

$xml = simplexml_load_file("test.xml");
print_r($xml);

This actually prints something but I couldn’t get past that or even echo it..

foreach($xml->text as $string) { 
  print_r($string);
  echo 'attributes: '. $string->attributes() .'<br />';
}

Didn’t work, originally it’s for strings but none of them are strings…

foreach ($xml->Formula as $element) {
  foreach($element as $key => $val) {
   echo "{$key}: {$val}";
  }

Didn’t work either, I needed something like this to work so I can use the values from the array without knowing what exactly the value will be called..

  • 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-10T10:19:09+00:00Added an answer on June 10, 2026 at 10:19 am

    You can’t access children by using a foreach on the node itself, you need to use .children():

    $s =<<<EOS
    <root>
    <Formula>
    <formulaname>Basic</formulaname>
    <movespeed>1</movespeed>
    <box>4</box>
    <chicken>3</chicken>
    <ducks>1</ducks>
    <cereal>2</cereal>
    </Formula>
    </root>
    EOS;
    
    $xml = simplexml_load_string($s);
    
    foreach ($xml->Formula as $element) {
        foreach($element->children() as $key => $val) {
            echo "{$key}: {$val}";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well I have been writing in the same style for awhile now and all
I have been having some issues with creating a connection to amazon's MWS service.
I've been having some major issues with a layout I'm making specifically in Internet
I'm having some issues wrapping my head around the concept of classloading, I've been
I'm having issues getting a simple server/client socket app working in C# between two
I have been working with pyinotify and I am having issues with it where
I have a WCF service that I am consuming, and have been doing well
I've been doing a little JavaScript (well, more like jQuery) for a while now
My IDE has been working very well, until today. When I try to compile
Well I was going to ask what the difference is but it's been answered

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.