我有一個for-each循環,內for-each循環處理for-each循環
類似於:
foreach ($arr1 as $v1) {
foreach ($v1 as $v2) {
[ processing goes here ]
}
}
現在我需要處理僅對第一外環,不是每隔一段時間。
我該怎麼辦?
我有一個for-each循環,內for-each循環處理for-each循環
類似於:
foreach ($arr1 as $v1) {
foreach ($v1 as $v2) {
[ processing goes here ]
}
}
現在我需要處理僅對第一外環,不是每隔一段時間。
我該怎麼辦?
$clone = $arr1; // clone for future use
foreach (array_shift($clone) as $v2) { // loop for first element of clone of $arr1, if starting index is known, $arr1[0] can be used instead of array_shift($clone)
[ processing goes here ]
}
$firstTime = true;
foreach ($arr1 as $v1) {
if($firstTime) {
$firstTime = false;
foreach ($v1 as $v2) {
[ processing goes here ]
}
}
}
foreach ($arr1 as $v1) {
foreach ($v1 as $v2) {
[ processing goes here ]
}
break;
}
或者你可能會做,簡單地說:
foreach ($arr1[0] as $v2) {
[ processing goes here ]
}