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

电玩女神 2023-03-05 12:46 22阅读 0赞

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:

句法:

  1. 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:

例子:

  1. Input:
  2. $arr1 = array(10, 20, 30, 40, 50);
  3. Output:
  4. 10
  5. Input:
  6. $arr2 = array("name" => "Amit", "age" => 21, "Gender" => "Male");
  7. Output:
  8. Amit

PHP code:

PHP代码:

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

Output

输出量

  1. 10
  2. Amit

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

current函数

发表评论

表情:
评论列表 (有 0 条评论,22人围观)

还没有评论,来说两句吧...

相关阅读