PHP | DOMNodeList count() Function Last Updated : 17 Mar, 2020 Comments Improve Suggest changes Like Article Like Report The DOMNodeList::count() function is an inbuilt function in PHP which is used to get the number of nodes in the list. Syntax: int DOMNodeList::count( void ) Parameters: This function doesn’t accept any parameter. Return Value: This function returns the number of nodes in the list. Below examples illustrate the DOMNodeList::count() function in PHP: Example 1: php <?php // Create a new DOMDocument instance $document = new DOMDocument(); // Create a div element $element = $document->appendChild(new DOMElement('div')); // Create a h1 element $text1 = new DOMElement('h1', 'GeeksforGeeks'); // Create another h1 elements $text2 = new DOMElement('h1', 'Another GeeksforGeeks'); // Append the nodes $element->appendChild($text1); $element->appendChild($text2); // Get all elements with tag name 'h1' $elements = $document->getElementsByTagName('h1'); // Count the elements echo $elements->count(); ?> Output: 2 Example 2: php <?php // Create a new DOMDocument instance $document = new DOMDocument(); // Create a div element $element = $document->appendChild(new DOMElement('div')); // Create a h1 element $text1 = new DOMElement('h1', 'GeeksforGeeks'); // Create another h1 elements $text2 = new DOMElement('h1', 'Another GeeksforGeeks'); // Append the nodes $element->appendChild($text1); $element->appendChild($text2); // Get all elements with tag name 'h1' $elements = $document->getElementsByTagName('h1'); // Count the elements echo 'Before removing: '; echo $elements->count() . "<br>"; // Remove a child $element->removeChild($text2); // Get all elements with tag name 'h1' $elements = $document->getElementsByTagName('h1'); // Count the elements echo 'After removing: '; echo $elements->count(); ?> Output: Before removing: 2 After removing: 1 Reference: https://www.php.net/manual/en/domnodelist.count.php Comment More infoAdvertise with us Next Article PHP | DOMNodeList count() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | DOMNode C14N() Function The DOMNode::C14N() function is an inbuilt function in PHP which is used to convert a node into string. Syntax: string DOMNode::C14N( bool $exclusive, bool $with_comments, array $xpath, array $ns_prefixes ) Parameters: This function accepts four parameters as mentioned above and described below: $ex 2 min read PHP | DOMNamedNodeMap count() Function The DOMNamedNodeMap::count() function is an inbuilt function in PHP which is used to get the number of nodes in the map. It can be used to count attributes of a element. Syntax: int DOMNamedNodeMap::count( void ) Parameters: This function doesnât accepts any parameter. Return Value: This function re 2 min read PHP DsSet count() Function The Ds\Set::count() function of Ds\Set class in PHP is an inbuilt function which is used to count the number of values present in the Set. This is also referred to as the size of the Set instance. Syntax: int public Ds\Set::count() Parameters: This function does not accept any parameter. Return Valu 1 min read PHP | DsDeque count() Function The Ds\Deque::count() function is an inbuilt function in PHP which is used to get the number of elements in the Deque. Syntax: public Ds\Deque::count( void ) : int Parameters: This function does not accept any parameter. Return Value: This function returns the number of elements in the Deque. Below 1 min read PHP | DsStack count() Function The Ds\Stack::count() function is an inbuilt function in PHP which is used to count the number of elements present in the Stack. Syntax: int Ds\Stack::count( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the number of elements present in the Stac 1 min read Like