Friday, January 23, 2026
HomeLanguagesPHP | DsDeque contains() Function

PHP | Ds\Deque contains() Function

The Ds\Deque::contains() function is an inbuilt function in PHP which is used to check if the element is present in the Deque or not.

Syntax:

public Ds\Deque::contains( $values ) : bool

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

Return Value: This function returns true if the element is present in the Deque, else returns false.

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

Program 1:




<?php
  
// Declare deque of default size
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]);
  
echo("Elements in the deque\n");
  
// Display the deque elements
var_dump($deck);
  
echo("\nChecking for the element in the deque\n");
  
// Use contains() function to check 3 is
// present in the deque or not
var_dump($deck->contains(3));
  
?>


Output:

Elements in the deque
object(Ds\Deque)#1 (6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
}

Checking for the element in the deque
bool(true)

Program 2:




<?php
  
// Declare deque of default size
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]);
  
echo("Elements in the deque\n");
  
// Display the deque elements
var_dump($deck);
  
echo("\nChecking for the element in the deque\n");
  
// Use contains() function to check 3 is
// present in the deque or not
var_dump($deck->contains("GFG"));
  
?>


Output:

Elements in the deque
object(Ds\Deque)#1 (6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
}

Checking for the element in the deque
bool(false)

Reference: http://php.net/manual/en/ds-deque.contains.php

RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 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
6912 POSTS0 COMMENTS