next函数_PHP next()函数与示例

next函数

PHP next()函数 (PHP next() function)

next() function firstly moves the current pointer to the next element and returns the element.

next()函数首先将当前指针移动到下一个元素,然后返回该元素。

Syntax:

句法:

    next(array);

Note: As we have discussed in the last post (current() function in PHP) that an array has a pointer that points to the first element by default, next() function can be used to move the pointer to next element and then print it.

注意:正如我们在上一篇文章( PHP中的current()函数 )中所讨论的那样,数组默认具有指向第一个元素的指针, next()函数可用于将指针移至下一个元素,然后进行打印它。

Examples:

例子:

    Input:
    $arr1 = array(10, 20, 30, 40, 50);
    Function call:
    next($arr1);
    Output:
    20

    Input:
    $arr2 = array("name" => "Amit", "age" => 21, "Gender" => "Male");
    Function call:
    next($arr2);
    Output:
    21

PHP code:

PHP代码:

<?php
    $arr1 = array(10, 20, 30, 40, 50);
    $arr2 = array("name" => "Amit", "age" => 21, "Gender" => "Male");
    
    echo current($arr1) . "\n"; //print first element
    echo next($arr1) ."\n"; //move to next element and print 
    echo next($arr1) ."\n"; //move to next element and print 

    echo current($arr2) . "\n"; //print first element
    echo next($arr2) ."\n"; //move to next element and print 
    echo next($arr2) ."\n"; //move to next element and print     
?>

Output

输出量

10
20
30
Amit
21
Male


翻译自: https://www.includehelp.com/php/next-function-with-example.aspx

next函数

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值