Saturday, May 23, 2026
HomeLanguagesPHP | DsSequence contains() Function

PHP | Ds\Sequence contains() Function

The Ds\Sequence::contains() function is an inbuilt function in PHP which is used to check the given value exists in the sequence or not.

Syntax:

bool abstract public Ds\Sequence::contains ([ mixed $...values ] )

Parameter: This function accepts single or many values which need to check the value exist in the sequence or not.

Return value: If value exist in the sequence then it returns True otherwise returns False.

Below programs illustrate the Ds\Sequence::contains() function in PHP:

Program 1:




<?php 
  
// Create a sequence 
$seq = new \Ds\Vector(['G', 'e', 'e', 'k', 's', 5, 2, 7]);
  
// Use contains() function to check elements
// exist in the sequence or not
var_dump($seq->contains('G')); 
  
var_dump($seq->contains('k'));
  
var_dump($seq->contains('p')); 
  
var_dump($seq->contains(7)); 
  
var_dump($seq->contains('5')); 
  
?> 


Output:

bool(true)
bool(true)
bool(false)
bool(true)
bool(false)

Program 2:




<?php 
  
// Create a sequence 
$seq = new \Ds\Vector(['G', 'e', 'e', 'k', 's', 5, 2, 7]);
  
// Use contains() function to check elements
// exist in the sequence or not
var_dump($seq->contains('G', 'e')); 
  
var_dump($seq->contains('k', 'e', 7));
  
var_dump($seq->contains('p', '1')); 
  
var_dump($seq->contains(7, 1)); 
  
var_dump($seq->contains('5', 5)); 
  
?> 


Output:

bool(true)
bool(true)
bool(false)
bool(false)
bool(false)

Reference: http://php.net/manual/en/ds-sequence.contains.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

4 COMMENTS

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS