Related Articles

Related Articles

PHP | Ds\Vector contains() Function
  • Last Updated : 22 Aug, 2019

The Ds\Vector::contains() function is an inbuilt function in PHP which is used to check the vector contains given value or not.

Syntax:

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

Parameters: This function accepts a single parameter $values which contains single/many values.

Return Value: This function returns true if the given value exists, false otherwise.

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



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a vector
$vector = new \Ds\Vector([1, 2, 3, 4, 5]);
  
// Use contains() function to check
// existence of vector elements
var_dump($vector->contains(1));
  
var_dump($vector->contains(1, 2));
  
var_dump($vector->contains(10));
  
?> 

chevron_right


Output:

bool(true)
bool(true)
bool(false)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a vector
$vector = new \Ds\Vector(["geeks", "for", "geeks"]);
  
// Use contains() function to check
// existence of vector elements
var_dump($vector->contains("geeks"));
  
var_dump($vector->contains("geeks", "for"));
  
var_dump($vector->contains("GfG"));
  
?>

chevron_right


Output:

bool(true)
bool(true)
bool(false)

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :