What is the correct way to access individual values in an XML file using PHP's SimpleXML?

When working with XML files in PHP using SimpleXML, you can access individual values by navigating through the XML structure using object properties and array indexes. To access a specific value, you can use the object properties or array indexes corresponding to the XML elements and attributes.

// Load the XML file
$xml = simplexml_load_file('data.xml');

// Access individual values
$value1 = $xml->elementName; // Accessing element value
$value2 = $xml->elementName['attributeName']; // Accessing attribute value

// Output the values
echo $value1;
echo $value2;