What is PHP | Ds\Set clear() function?

What is PHP?

PHP is a scripting language that allows web developers to create effective and interactive web pages that deal with databases. It acts as a competitive alternative to Microsoft ASP. It is an open-source scripting language that acts as a core part of WordPress and helps run one of the largest and most popular social networks: Facebook.

PHP code runs on the server and the browser receives the output as HTML. PHP can perform a variety of diverse functions, such as collecting form data, updating the data in a database, creating and updating files on the server, as well as controlling user access. It is able to run on most operating systems and servers, making it highly compatible.

PHP functions

PHP has more than a thousand inbuilt functions and enables its developers to create their own functions as well. Functions are considered one of the extraordinary strengths of PHP.

Functions are basically a structure of code that can be used repetitively. Functions need to be called in order to achieve their specific task.

Creating a function in PHP

Creating a function callEducative() which prints “Welcome to Educative!

<?php
function callEducative() {
echo "Welcome to Educative!";
}
callEducative(); // function call
?>

What is the Ds\Set clear() function?

It is an inbuilt function that clears the set by removing all of its values.

void public Ds\Set::clear( void )

Coded example

The following example shows clear() function in action.

<?php
$set = new \Ds\Set([50, 40, 30, 20, 10]);
// Display before clearing
print_r($set);
$set->clear();
// Display after clearing
print_r($set);
?>

Output before clear() is called

Ds\Set Object

[0] => 50
[1] => 40
[2] => 30
[3] => 20
[4] => 10

Output after clear() is called

Ds\Set Object

No display as the set has no elements after the clear() function is applied.