each() 函數(shù)返回?cái)?shù)組中當(dāng)前的鍵/值對(duì)并將數(shù)組指針向前移動(dòng)一步
each ( $array );
each()函數(shù)從數(shù)組數(shù)組返回當(dāng)前鍵和值對(duì),并前進(jìn)數(shù)組光標(biāo)。該對(duì)以四元素?cái)?shù)組形式返回,鍵為0、1,鍵和值。元素0和key包含數(shù)組元素的鍵名,元素1和value包含數(shù)據(jù)。
序號(hào) | 參數(shù)及說(shuō)明 |
---|---|
1 | array(必需) 它指定一個(gè)數(shù)組 |
它從數(shù)組返回當(dāng)前鍵和值對(duì)。
<?php $transport = array('foot', 'bike', 'car', 'plane'); $key_value = each($transport); print_r($key_value); print "<br />"; $key_value = each($transport); print_r($key_value); print "<br />"; $key_value = each($transport); print_r($key_value); ?>測(cè)試看看?/?
輸出結(jié)果:
Array ( [1] => foot [value] => foot [0] => 0 [key] => 0 ) Array ( [1] => bike [value] => bike [0] => 1 [key] => 1 ) Array ( [1] => car [value] => car [0] => 2 [key] => 2 )