Home  >  Article  >  Backend Development  >  How to use each function

How to use each function

藏色散人
藏色散人Original
2019-02-14 14:57:059200browse

PHP each() function returns the current key/value pair in the array and moves the array pointer forward one step.

How to use each function

php each() function syntax

Function: Return the key name and key value of the current element, and move the internal pointer forward

Syntax:

each(array)

Parameters:

array Required. Specifies the array to use.

Description: Generate an array consisting of the key name and key value of the element pointed to by the current internal pointer of the array, and move the internal pointer forward. The returned array contains four elements: key 0, 1, key and value. Cells 0 and key contain the key names of the array cells, and 1 and value contain the data. If the internal pointer exceeds the range of the array, this function returns FALSE.

php each() function example 1

<?php
$a=array("php中文网","西门","讲师","灭绝师太","无忌哥哥");
print_r(each($a));
?>

Output:

Array ( [1] => php中文网 [value] => php中文网 [0] => 0 [key] => 0 )

php each() function example 2

<?php
$a=array("无忌哥哥","灭绝师太","讲师","php中文网","西门");
print_r(each($a));
?>

Output:

Array ( [1] => 无忌哥哥 [value] => 无忌哥哥 [0] => 0 [key] => 0 )

This article is an introduction to the PHP each function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use each function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn