Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
count
communitycreator

What is the PHP Ds\Set count() function?

Saad Akbar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Ds\Set count() is an inbuilt function in PHP used to sum up the number of values stored in a set.

Syntax

int public Ds\Set::count()

Parameters

The function takes in no parameters.

Return value

The function returns the number of values in the set.

Code

The following code counts elements using the count() function and prints all of the elements.

<?php 
  
$set = new \Ds\Set(["Learn", "PHP", "from", "Educative"]); 
  
// Show the elements of the set 
var_dump($set); 
  
//Number of elements in the set
echo "Count is : ";
print_r($set->count());
  
?> 

Expected output

object(Ds\Set)#1 (4) 
  
- [0]=> string(5) "Learn"

- [1]=> string(3) "PHP"

- [2]=> string(4) "from"

- [3]=> string(9) "Educative"

- Count is :  4

RELATED TAGS

php
count
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring