processing only for first outer for-each loop
I have a for-each 开发者_如何学Cloop, within for-each loop
similar to:
foreach ($arr1 as $v1) {
foreach ($v1 as $v2) {
[ processing goes here ]
}
}
Now I need to processing only for first outer loop, not for every other time.
How can I do it?
foreach ($arr1 as $v1) {
foreach ($v1 as $v2) {
[ processing goes here ]
}
break;
}
Or you might do, simply:
foreach ($arr1[0] 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 ]
}
}
}
精彩评论