How can the end tag be included when creating XML elements using XMLWriter in PHP?

When creating XML elements using XMLWriter in PHP, the end tag can be included by calling the `endElement()` method after adding the element's content. This method will automatically close the current element by adding the appropriate end tag.

$xml = new XMLWriter();
$xml->openMemory();
$xml->startDocument();
$xml->startElement('root');
$xml->writeElement('child', 'content');
$xml->endElement(); // Close the 'child' element
$xml->endElement(); // Close the 'root' element
echo $xml->outputMemory();