Thursday, January 29, 2026
HomeLanguagesPHP | DsCollection isEmpty() Function

PHP | Ds\Collection isEmpty() Function

The Ds\Collection::isEmpty() function is an inbuilt function in PHP which is used to returns whether collection is empty.

Syntax:

Ds\Collection::isEmpty ( void ) : bool

Parameters: This function does not accepts any parameters.

Return Value: It returns True if collection is empty or False otherwise.

Below programs illustrate the Ds\Collection::isEmpty() function in PHP:

Example 1:




<?php
  
// Create a collection
$collection = new \Ds\Vector([10, 15, 21, 13, 16, 18]);
  
// Use isEmpty function
$res = $collection->isEmpty();
  
// Display the result
var_dump($res);
  
// Create a collection
$collection = new \Ds\Vector();
  
// Use isEmpty function
$res = $collection->isEmpty();
  
// Display the result
var_dump($res);
?>


Output:

bool(false) 
bool(true) 

Example 2:




<?php
  
// Create a collection
$collection = new \Ds\Vector();
  
// display output
var_dump($collection->isEmpty());
  
// Create a collection
$collection = new \Ds\Vector([1, 3, 5, 2, 6]);
  
// Display output
var_dump($collection->isEmpty());
  
?>


Output:

bool(true) 
bool(false) 

Reference: http://php.net/manual/en/ds-collection.isempty.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32476 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6848 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7221 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6916 POSTS0 COMMENTS