當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP Ds\Vector first()用法及代碼示例

Ds \ Vector::first()函數是PHP中的內置函數,用於查找向量中的第一個元素。

用法:

mixed public Ds\Vector::first( void )

參數:該函數不接受任何參數。


返回值:此函數返回向量中存在的第一個元素。

以下示例程序旨在說明PHP中的Ds \ Vector::first()函數:

程序1:

<?php 
  
// Create vector elements 
$vector = new \Ds\Vector([1, 2, 3, 4, 5]); 
  
  
echo("First element of the vector:"); 
  
// Use first() function to find 
// the first element 
var_dump($vector->first()); 
  
?>

輸出:

First element of the vector:int(1)

程序2:

<?php 
  
// Create vector elements 
$vector = new \Ds\Vector(["geeks", "for", "geeks"]); 
  
  
echo("First element of the vector:"); 
  
// Use first() function to find 
// the first element 
var_dump($vector->first()); 
  
?>

輸出:

First element of the vector:string(5) "geeks"

參考: http://php.net/manual/en/ds-vector.first.php



相關用法


注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 PHP | Ds\Vector first() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。