How to use each function

藏色散人
Release: 2023-04-05 08:18:02
Original
9262 people have browsed it

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)
Copy after login

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));
?>
Copy after login

Output:

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

php each() function example 2

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

Output:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template