Related Articles

Related Articles

PHP | Ds\Deque contains() Function
  • Last Updated : 30 Jan, 2019

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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));
  
?>

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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"));
  
?>

chevron_right


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




My Personal Notes arrow_drop_up
Recommended Articles
Page :