foreach循环中最后一个循环的值
foreach循环中最后一个循环的值原始代码:
<?php
$i = count($myArray);
foreach ($myArray as $item) {
/** code goes here... */
$i--;
if ($i == 0) {
/** something happens here */
}
}
?>
最后一个值
if ($item === end($myArray)) {
// Last item
}第一个值
if ($item === reset($myArray)) {
// First item
}
页:
[1]