This article mainly introduces the foreach each list about PHP, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it
<?php /*foreach (函数名 as 地址下标 => 该下标对应的数值) $arr = ['a','b','c','d','e','f','g']; foreach( $arr as $key=>$val) { var_dump($key.'--------'.$val.'<br />'); }
The use of list is similar to directly copying the value in the array to the variable of the list, and then outputting
$arr = ['a','b','c','d','e','f','g']; list($a,$b,$c,$d,$e) = $arr; var_dump($a,$b,$c,$d,$e);
Each is equivalent It is used to read by row, but this is to read the data corresponding to the address one by one
$arr = ['abc','b','c','d','e','f','g']; var_dump(each($arr)); var_dump(each($arr)); var_dump(each($arr)); var_dump(each($arr)); var_dump(each($arr));
This is a combination of list and each, similar to the use of foreach When the output address is the same as the corresponding value
$arr = ['abc','b','c','d','e','f','g']; list($key,$val) = each($arr); var_dump($key,$val); list($key,$val) = each($arr); var_dump($key,$val); list($key,$val) = each($arr); var_dump($key,$val); list($key,$val) = each($arr); var_dump($key,$val); ?> */
The above is the detailed content of PHP的 foreach each list. For more information, please follow other related articles on the PHP Chinese website!