Sunday, February 22, 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
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS