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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:41:30+00:00 2026-06-12T21:41:30+00:00

I have two homework problems for school, and i have looked over them several

  • 0

I have two homework problems for school, and i have looked over them several times and didn’t get it

I have this array

Array[10][10][10]

id  parent  value
1   0       X
2   1       Y
3   1       Z
4   3       A
5   2       B
6   5       C
7   3       D
8   9       E
9   4       F
10  2       G

What i want is to generate a sitemap based on parent column.

Example
1 must be at the root
2 and 3 must be childs of 1
10 and 5 must be childs of 2
... and so on.

I would like if i could generate an .xml like

<object id="1" value="X">
    <object id="2" value="Y">
        <object id="10" value="G">
        </object>
        <object id="5" value="B">
        </object>

        ... and so on ...

    </object>
</object>

and an array

array(
    id = > 1
    array
);

i don’t look how it might actually look, maybe something like this

$array = array(
    "foo" => "bar",
    42    => 24,
    "multi" => array(
         "dimensional" => array(
             "array" => "foo"
         )
    )
);

and the second problem i will post it later. I’m using PHP for this, but C++ and C# would work as well, because the algorithm is important. Any help would be apreciated, because i’m very curious about this!

  • 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-12T21:41:32+00:00Added an answer on June 12, 2026 at 9:41 pm

    I believe your array looks like this

    $list = array();
    $list[] = array("id" => 1,"parent" => 0,"value" => "X");
    $list[] = array("id" => 2,"parent" => 1,"value" => "Y");
    $list[] = array("id" => 3,"parent" => 1,"value" => "Z");
    $list[] = array("id" => 4,"parent" => 3,"value" => "A");
    $list[] = array("id" => 5,"parent" => 2,"value" => "B");
    $list[] = array("id" => 6,"parent" => 5,"value" => "C");
    $list[] = array("id" => 7,"parent" => 3,"value" => "D");
    $list[] = array("id" => 8,"parent" => 9,"value" => "E");
    $list[] = array("id" => 9,"parent" => 4,"value" => "F");
    $list[] = array("id" => 10,"parent" => 2,"value" => "G");
    

    You can try

    $xml = new SimpleXMLElement("<data />");
    startBuild($list, $xml);
    header("Content-Type: text/xml");
    echo $xml->asXML();
    

    Output

    <?xml version="1.0"?>
    <data> <object id="1" value="X">
        <object id="2" value="Y">
            <object id="5" value="B">
                <object id="6" value="C" />
            </object>
            <object id="10" value="G" />
        </object>
        <object id="3" value="Z">
            <object id="4" value="A">
                <object id="9" value="F">
                    <object id="8" value="E" />
                </object>
            </object>
            <object id="7" value="D" />
        </object>
    </object> 
    </data>
    

    Function Used

    function startBuild(array $array, SimpleXMLElement $xml, $no = 0) {
        $child = hasChildren($array, $no);
        if (empty($child))
            return "";
    
        foreach ( $child as $value ) {
            $xChild = $xml->addChild("object");
            $xChild->addAttribute("id", $value['id']);
            $xChild->addAttribute("value", $value['value']);
            startBuild($array, $xChild, $value['id']);
        }
        return true;
    }
    
    function hasChildren($array, $id) {
        return array_filter($array, function ($var) use($id) {
            return $var['parent'] == $id;
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: This is a homework assignment. I have two classes, one inherits from the
I have two questions about this homework assignment: Write an assembly language program in
Is it possible in C++ to have two classes, let's call them A and
I have this homework problem where I need to use regex to remove every
I am stumped on this homework problem. I think I have the right answer
This is a homework problem that i have been asked to do. Create an
I've got a homework assignment where I have a base class Package, and two
Before I start, yes this is a homework. I would not have posted here
Continuing on this problem , but I'll reiterate: For a homework assignment I have
Have two folders with approx. 150 java property files. In a shell script, how

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.