I have a problem. I am struggling for a few days now to create a well formatted XML. I already created this code, but I have no idea if this is what I need:
$sql = "SELECT * FROM Contacts ORDER BY Id ASC";
$result = $conn->query($sql);
$arr_contacts = array();
while ($row = mysqli_fetch_assoc($result))
{
$contact_array = array(
$row["Id"]=>array(
'id'=>$row["Id"],
'name'=>$row["Name"])
);
$arr_contacts = array_merge($arr_contacts, $contact_array);
}
Now I want a XML like this:
<?xml version="1.0"?>
<Contacts>
<Contact>
<id>1</id>
<name>Smith</name>
</Contact>
<Contact>
<id>2</id>
<name>John</name>
</Contact>
<Contact>
<id>3</id>
<name>Viktor</name>
</Contact>
</Contacts>
The problem is that I don't understand XML very well, so my result is as following:
1Smith2John3Viktor
I used his code: https://www.codexworld.com/convert-array-to-xml-in-php/
How can I get the result I want?