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

current函数

PHP current()函数 (PHP current() function)

An array in PHP has a current pointer which points to the first element by default, current() function is used to get the current elements of an array. It accepts an array and returns its current element.

PHP中的数组具有当前指针,该指针默认情况下指向第一个元素, current()函数用于获取数组的当前元素。 它接受一个数组并返回其当前元素。

Syntax:

句法:

    current(array);

Note:

注意:

  • In an array which contains keys and values, it returns only value not a key.

    在包含键和值的数组中,它仅返回值,而不返回键。

  • current() returns only the current element, it does not move the pointer to next element.

    current()仅返回当前元素,它不会将指针移动到下一个元素。

Examples:

例子:

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

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

PHP code:

PHP代码:

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

Output

输出量

10
Amit


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

current函数

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值