📜  PHP |每个()函数

📅  最后修改于: 2022-05-13 01:56:39.622000             🧑  作者: Mango

PHP |每个()函数

each()函数是PHP中的一个内置函数,它基本上返回一个包含四个元素的数组,两个元素(1 和 Value)作为元素值,两个元素(0 和 Key)作为元素键并向前移动光标。
句法:

each(array)

参数:

Array:
It specifies the array which is being 
taken as input and used for each() function.

返回值:

It returns the current element key and value which are an array with four elements out of
which two elements (1 and Value) for the element value, and two elements (0 and Key) for 
the element key.It returns FALSE if there are no array elements.

PHP版本:
4+
让我们看看PHP程序:
方案一:


输出:
Array
(
    [1] => Ram
    [value] => Ram
    [0] => 0
    [key] => 0
)
Array
(
    [1] => Shita
    [value] => Shita
    [0] => 1
    [key] => 1
)

方案二:

"Ram", "105"=>"Geeta", "104"=>"Geek");
  
// each() function return in the array with four elements
// Two elements (1 and Value) for the element value which 
// are Ram, and two  elements (0 and Key) for the element 
// key which are Boy.
print_r (each($a));
  
// Next set is printed as cursor is moved
print_r (each($a));
?>
输出:
Array
(
    [1] => Ram
    [value] => Ram
    [0] => 101
    [key] => 101
)
Array
(
    [1] => Geeta
    [value] => Geeta
    [0] => 105
    [key] => 105
)

参考:
PHP 。 PHP