PHP Ds Deque find()函数用法代码示例

2021年3月20日15:42:48 发表评论 874 次浏览

Ds \ Deque :: find()function是PHP中的内置函数, 用于在Deque中找到元素时在Deque中查找元素的索引。

语法如下:

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

参数:该函数接受单个参数$值其中包含要查找其索引的元素。

返回值:如果element存在, 则此函数返回元素的索引, 否则返回false。

下面的程序说明了Ds \ Deque :: find()PHP中的功能:

程序1:

<?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 ( "\nInex of 3 in the deque: " );
  
// Use find() function to find 
// the index of element
print_r( $deck ->find(3));
  
?>

输出如下:

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

Inex of 3 in the deque: 2

程式2:

<?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 ( "\nInex of 3 in the deque: " );
  
// Use find() function to find 
// the index of element
var_dump( $deck ->find( "ABC" ));
  
?>

输出如下:

Elements in the Deque
Ds\Deque Object
(
    [0] => Geeks
    [1] => for
    [2] => GFG
)

Inex of 3 in the deque: bool(false)

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


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: