php有next,PHP next()用法及代码示例

next()函数是PHP中的内置函数,它执行以下操作:

它用于返回内部指针当前指向的数组中下一个元素的值。我们可以通过当前函数知道当前元素。

返回值后,next()函数使内部指针递增。

在PHP中,所有数组都有一个内部指针。此内部指针指向该数组中的某个元素,该元素称为数组的当前元素。

通常,开头的下一个元素是数组中插入的第二个元素。

用法:

next($array)

参数:它仅接受一个参数$array。此参数是必需的。它是我们需要在其中找到下一个元素的数组。

返回值:该函数返回内部指针当前指向的数组中下一个元素的值。如果下一个没有元素,则返回FALSE。最初,next()函数返回第二个插入的元素。

例子:

Input : array = [1, 2, 3, 4]

Output : 2

Input : array = [1, 2, 3, 4], next() function executed two times

Output : 2

3

以下示例程序旨在说明PHP中的next()函数:

程序1:

// PHP Program to demonstrate the

// first position of next() function

$array = array("geeks", "Raj", "striver",

"coding", "RAj");

echo next($array);

?>

输出:

Raj

程序2:

// PHP Program to demonstrate the

// working of next() function

$array = array("geeks", "Raj", "striver", "coding", "RAj");

// prints the initial current element (geeks)

echo current($array), "\n";

// prints the initial next element (Raj)

// moves the pointer forward

echo next($array), "\n";

// prints the  current element (Raj)

echo current($array), "\n";

// prints the  next element (striver)

// moves the pointer forward

echo next($array), "\n";

// prints the  current element (striver)

echo current($array), "\n";

// prints the  next element (coding)

// moves the pointer forward

echo next($array), "\n";

// prints the  current element (coding)

echo current($array), "\n";

?>

输出:

geeks

Raj

Raj

striver

striver

coding

coding

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值