Open In App

PHP | Ds\Deque contains() Function

Last Updated : 30 Jan, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads