What is the best way to read all data of an entry in a PHP SimpleXML object in a specific order?

When working with a PHP SimpleXML object, the data within an entry may need to be read in a specific order. To achieve this, you can loop through the child elements of the entry and store their values in an array. Then, you can access the values in the desired order by referencing the array elements.

// Assuming $entry is the SimpleXML object representing the entry
$data = [];

// Loop through the child elements of the entry and store their values in an array
foreach ($entry->children() as $child) {
    $data[$child->getName()] = (string) $child;
}

// Access the values in the desired order by referencing the array elements
echo $data['element1'];
echo $data['element2'];
echo $data['element3'];