PHP Ds Sequence first()函数介绍和用法

2021年3月12日13:10:32 发表评论 654 次浏览

Ds \ Sequence :: first()function是PHP中的内置函数, 用于返回序列中的第一个元素。

语法如下:

mixed abstract public Ds\Sequence::first ( void )

参数:该函数不接受任何参数。

返回值:此函数返回序列中的第一个元素。

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

范例1:

<?php
  
// Create new sequence
$seq =  new \Ds\Vector([10, 20, 13, 25]);
  
// Display the first element from the sequence
var_dump( $seq ->first());
  
// Create new sequence
$seq =  new \Ds\Vector([ 'G' , 'e' , 'e' , 'k' , 's' ]);
  
// Display the first element from the sequence
var_dump( $seq ->first());
  
?>

输出如下:

int(10)
string(1) "G"

范例2:

<?php
  
// Create new sequence
$seq =  new \Ds\Vector([21, 23, 'p' , 'x' ]);
  
// Display the first element
// from the sequence
var_dump( $seq ->first());
  
// Function to push an element
$seq ->insert(0, "G" );   
  
// Display the first element
// from the sequence
var_dump( $seq ->first());
  
?>

输出如下:

int(21)
string(1) "G"

参考: http://php.net/manual/en/ds-sequence.first.php


木子山

发表评论

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