PHP - Ds\Pair::clear() Function



The PHP Ds\Pair::clear() function is used to remove all values from the pair. Once this function is invoked on the current pair, it will become empty. You can verify this using the isEmpty() function, which returns 'true' if the pair is empty and 'false' otherwise.

The clear() function of the pair class is not available in the latest PHP version. Ensure that you have the appropriate version of PHP installed in your system, or else you will face some error-related issues.

Syntax

Following is the syntax of the PHP Ds\Pair::clear() function −

public void Ds\Pair::clear( void )

Parameters

This function does not accept any parameter.

Return value

This function does not return any value.

Example

The following is the basic example of the PHP Ds\Pair::clear() function −

<?php  
   $pair = new \Ds\Pair("TP", "TutorialsPoint");
   echo ("The original pair elements are: \n");  
   print_r($pair);
   #using clear() function
   $pair->clear();
   echo "The pair after clear: \n";
   print_r($pair);
?>

Output

As this function does not available the latest version of PHP, it will throw an error as follows −

The original pair elements are:
Ds\Pair Object
(
    [key] => TP
    [value] => TutorialsPoint
)
PHP Fatal error:  Uncaught Error: Call to undefined method Ds\Pair::clear() in 
C:\Apache24\htdocs\index.php:6
Stack trace:
#0 {main}
  thrown in C:\Apache24\htdocs\index.php on line 6
php_function_reference.htm
Advertisements