我有一个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 ]
}