PHP | SplFixedArray current()函数用法介绍

SplFixedArray :: current()function是PHP中的内置函数, 用于获取数组的当前条目。
语法如下:

mixed SplFixedArray::current()

参数:此函数不接受任何参数。
返回值:此函数返回数组的当前条目。
下面的程序说明了SplFixedArray :: current()PHP中的功能:
程序1:
< ?php// Create some fixed size array $gfg = new SplFixedArray(6); $gfg [0] = 1; $gfg [1] = 5; $gfg [2] = 1; $gfg [3] = 11; $gfg [4] = 15; $gfg [5] = 17; $gfg -> next(); echo $gfg -> current(). "\n" ; $gfg -> rewind (); echo $gfg -> current(). "\n" ; ?>

输出如下:
5 1

程式2:
< ?php// Create some fixed size array $gfg = new SplFixedArray(6); $gfg [0] = 1; $gfg [1] = 5; $gfg [2] = 1; $gfg [3] = 11; $gfg [4] = 15; $gfg [5] = 17; // Iterate array and print its values while ( $gfg -> valid() ) { echo $gfg -> current() . "\n" ; $gfg -> next(); } ?>

输出如下:
1 5 1 11 15 17

【PHP | SplFixedArray current()函数用法介绍】参考: https://www.php.net/manual/en/splfixedarray.current.php

    推荐阅读