(PHP 8 >= 8.3.0)
DOMElement::toggleAttribute — Alterna atributo
Toggle the attribute.
Retorna true
se o atributo estiver presente após a conclusão da chamada, false
caso contrário.
Exemplo #1 DOMElement::toggleAttribute() exemplo
<?php
$dom = new DOMDocument();
$dom->loadXML("<?xml version='1.0'?><container selected=\"\"/>");
var_dump($dom->documentElement->toggleAttribute('selected'));
echo $dom->saveXML() . PHP_EOL;
var_dump($dom->documentElement->toggleAttribute('selected'));
echo $dom->saveXML();
?>
O exemplo acima produzirá:
bool(false) <?xml version="1.0"?> <container/> bool(true) <?xml version="1.0"?> <container selected=""/>