How can PHP be used to access and update data from an XML file?

To access and update data from an XML file using PHP, you can use the SimpleXML extension which provides a simple and easy way to handle XML data. You can use SimpleXML to load the XML file, navigate through its elements, retrieve data, and make changes to the XML structure. By using SimpleXML functions like simplexml_load_file() to load the XML file and accessing elements using object properties, you can easily manipulate XML data within your PHP code.

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

// Access and update data
$xml->book[0]->title = 'New Title';
$xml->book[0]->author = 'New Author';

// Save the changes back to the XML file
$xml->asXML('data.xml');