Open In App

PHP | Ds\Deque find() Function

Last Updated : 24 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The Ds\Deque::find() function is an inbuilt function in PHP which is used to find the index of the element in the Deque if element found in the Deque.
Syntax: 
 

public Ds\Deque::find( $value ) : mixed

Parameters: This function accepts single parameter $value which holds the element whose index is to be found.
Return Value: This function returns the index of the element if element exist, else returns false.
Below programs illustrate the Ds\Deque::find() function in PHP:
Program 1: 
 

PHP




<?php
 
// Declare a deque
$deck = new \Ds\Deque([10, 20, 3, 40, 50, 6]);
 
echo("Elements in the Deque\n");
 
// Display the Deque elements
print_r($deck);
 
echo("\nIndex of 3 in the deque: ");
 
// Use find() function to find
// the index of element
print_r($deck->find(3));
 
?>


Output:

Elements in the Deque
Ds\Deque Object
(
   [0] => 10
   [1] => 20
   [2] => 3
   [3] => 40
   [4] => 50
   [5] => 6
)
Index of 3 in the deque: 2

Program 2: 

PHP




<?php
 
// Declare a deque
$deck = new \Ds\Deque(["Geeks", "for", "GFG"]);
 
echo("Elements in the Deque\n");
 
// Display the Deque elements
print_r($deck);
 
echo("\nIndex of 3 in the deque: ");
 
// Use find() function to find
// the index of element
var_dump($deck->find("ABC"));
 
?>


Output:

Elements in the Deque
Ds\Deque Object
(
   [0] => Geeks
   [1] => for
   [2] => GFG
)
Index of 3 in the deque: bool(false)

Reference: http://php.net/manual/en/ds-deque.find.php
 



Similar Reads

PHP | Ds\Deque pop() Function
The Ds\Deque::pop() function is an inbuilt function in PHP which is used to remove the last element from Deque (if Deque is not empty) and return it. If Deque is empty then it throws an exception. Syntax: public Ds\Deque::pop( void ) : mixed Parameters: This function does not accept any parameter. Return Value: This function returns the removed las
2 min read
PHP | Ds\Deque capacity() Function
The Ds\Deque::capacity() function is an inbuilt function in PHP which is used to get the current capacity of the Deque. Syntax: public Ds\Deque::capacity( void ) : int Parameters: This function does not accepts any parameter. Return Value: This function returns the current capacity of the Deque. Below programs illustrate the Ds\Deque::capacity() fu
1 min read
PHP | Ds\Deque get() Function
The Ds\Deque::get() function is an inbuilt function in PHP which is used to return the value at the given index. Syntax: public Ds\Deque::get( $index ) : mixed Parameters: This function accepts single parameter $index which holds the index for which element is to be found. Return Value: This function returns the value at given index. Below programs
2 min read
PHP | Ds\Deque isEmpty() Function
The Ds\Deque::isEmpty() function is an inbuilt function in PHP which is used to check the Deque is empty or not. Syntax: public Ds\Deque::isEmpty( void ) : bool Parameters: This function does not accept any parameter. Return Value: This function returns true if the Deque is empty, else return false. Below programs illustrate the Ds\Deque::isEmpty()
1 min read
PHP | Ds\Deque map() Function
The Ds\Deque::map() function is an inbuilt function in PHP which is used to return the Deque with each element modified on the basis of operation performed as per the callback function. Syntax: public Ds\Deque::map( $callback ) : Ds\Deque Parameters: This function accepts single parameter $callback which contains the callable function on the operat
2 min read
PHP | Ds\Deque insert() Function
The Ds\Deque::insert() function is an inbuilt function in PHP which is used to insert the value at the given index in the Deque. Syntax: public Ds\Deque::insert( $index, $values ) : void Parameters: This function accepts two parameter as mentioned above and described below: $index: This parameter holds the index at which element is to be inserted.
2 min read
PHP | Ds\Deque count() Function
The Ds\Deque::count() function is an inbuilt function in PHP which is used to get the number of elements in the Deque. Syntax: public Ds\Deque::count( void ) : int Parameters: This function does not accept any parameter. Return Value: This function returns the number of elements in the Deque. Below programs illustrate the Ds\Deque::count() function
1 min read
PHP | Ds\Deque filter() Function
The Ds\Deque::filter() function is an inbuilt function in PHP which is used to filter out the elements from the deque based on the operation defined in the callback function. Syntax: public Ds\Deque::filter( $callback ) : Ds\Deque Parameters: This function accepts single parameter $callback which is the callback function which contains the definiti
2 min read
PHP | Ds\Deque allocate() Function
The Ds\Deque::allocate() function is an inbuilt function in PHP which is used to allocate memory as specified in the argument. If the argument is not defined, then the Deque of default size will be created. Syntax: public Ds\Deque::allocate( $capacity ) : void Parameters: This function accepts single parameter $capacity which holds the number of va
1 min read
PHP | Ds\Deque apply() Function
The Ds\Deque::apply() function is an inbuilt function in PHP which is used to update the values of Deque by performing operations as defined by the callback function. Syntax: public Ds\Deque::apply( $callback ) : void Parameters: This function accepts single parameter $callback which holds the function define the operation to be performed on each e
2 min read