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函数
还没有评论,来说两句吧...