PHP 8.4.1 Released!

DOMElement::toggleAttribute

(PHP 8 >= 8.3.0)

DOMElement::toggleAttributeToggle attribute

Açıklama

public DOMElement::toggleAttribute(string $qualifiedName, ?bool $force = null): bool

Toggle the attribute.

Bağımsız Değişkenler

qualifiedName

The qualified name of the attribute.

force

  • if null, the function will toggle the attribute.
  • if true, the function adds the attribute.
  • if false, the function removes the attribute.

Dönen Değerler

Returns true if the attribute is present after finishing the call, false otherwise.

Örnekler

Örnek 1 DOMElement::toggleAttribute() example

<?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();
?>

Yukarıdaki örneğin çıktısı:

bool(false)
<?xml version="1.0"?>
<container/>

bool(true)
<?xml version="1.0"?>
<container selected=""/>
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top