The each()
function in PHP is used to fetch the key-value pair from an array and move the internal pointer of the array forward. It returns the current key-value pair and moves the pointer to the next pair.
Here is the syntax of the each()
function:
each(array $array): array|false
Parameters:
$array
: The input array.Return Value:
false
if there are no more elements in the array.Example:
$fruits = array("apple", "banana", "orange");
$fruit = each($fruits);
print_r($fruit);
Output:
Array
(
[1] => apple
[value] => apple
[0] => 0
[key] => 0
)
In the above example, the each()
function returns the first key-value pair from the $fruits
array. The returned array contains the value (apple
), the key (0
), and their respective indexes (1
and 0
).
下一篇:php strpos
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站