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:

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

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.