PHP | Ds\Sequence find() Function

The Ds\Sequence::find() function is an inbuilt function in PHP which is used to find the value from the sequence. If the value present in the sequence then return its index value otherwise return false.

Syntax:

mixed abstract public Ds\Sequence::find ( mixed $value ) 

Parameter: This function accepts single parameter $value which need to check that it present in the sequence or not.



Return value: This function returns the index of value on success or False on failure.

Below programs illustrate the Ds\Sequence::find() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create new sequence
$seq new \Ds\Vector([21, 23, "p", "x"]);
  
// Use find() function
var_dump($seq->find("G"));
  
// Use find() function
var_dump($seq->find(21));
  
// Use find() function
var_dump($seq->find(10));
  
// Use find() function
var_dump($seq->find("x"));
  
// Use find() function
var_dump($seq->find("p"));
  
?>

chevron_right


Output:

bool(false)
int(0)
bool(false)
int(3)
int(2)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create new sequence
$seq new \Ds\Vector(["G", "E", "E",
        "K", "S", "1", "2", 1, 2, 3, 4]);
  
// Use find() function
var_dump($seq->find("G"));
  
// Use find() function
var_dump($seq->find(1));
  
// Use find() function
var_dump($seq->find(10));
  
// Use find() function
var_dump($seq->find("1"));
  
// Use find() function
var_dump($seq->find("k"));
  
// Use find() function
var_dump($seq->find("F"));
  
// Use find() function
var_dump($seq->find("4"));
  
?>

chevron_right


Output:

int(0)
int(7)
bool(false)
int(5)
bool(false)
bool(false)
bool(false)

Reference: http://php.net/manual/en/ds-sequence.find.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.