PHP is a scripting language that allows web developers to create effective and interactive web pages that deal with databases. PHP 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 Facebook, one of the largest and most popular social networks.
PHP provides a built-in library called data structures. The data structures library provides efficient data structures beyond the arrays to streamline the workflow in PHP and make it more efficient. Among several data structures, the library provides Ds\Set
, which is an implementation of sets. In this shot, we are going to discuss the capacity()
function of the Ds\Set
class.
capacity()
functionpublic Ds\Set::capacity(): int
The capacity()
function does not take any parameters and returns the capacity of the set.
The code below shows the implementation for the capacity()
function.
<?php$set = new \Ds\Set([8, 7, 6, 5, 4, 3]);echo("Set Elements\n");// Print Set elementsvar_dump($set);echo("\nSet Capacity: ");// Print the capacity of setvar_dump($set->capacity());?>
Set Elements
object(Ds\Set)#1 (6)
{
[0] => int(8)
[1] => int(7)
[2] => int(6)
[3] => int(5)
[4] => int(4)
[5] => int(3)
}
Set Capacity: int(8)
First, we declare the set and populate it with elements. Then, we display the elements. We call the capacity()
function to print the capacity of the set.