I use foreach loop but it always gives an wierd result in the first but others are fine so i want to remove 1st loop and continue from 2nd...
My code is
foreach($doc->getElementsByTagName('a') as $a){
foreach($a->getElementsByTagName('img') as $img){
echo $a->getAttribute('href');
echo $img->src . '<br>';
}
}
The answer here is to use foreach with a LimitIterator . Show activity on this post. The continue causes the foreach to skip back to the beginning and move on to the next element in the array. It's extremely useful for disregarding parts of an array which you don't want to be processed in a foreach loop.
break ends execution of the current for , foreach , while , do-while or switch structure.
$counter = 0;
foreach($doc->getElementsByTagName('a') as $a){
foreach($a->getElementsByTagName('img') as $img){
if ($counter++ == 0) continue;
echo $a->getAttribute('href');
echo $img->src . '<br>';
}
}
The simplest way I can think of in order to skip the first loop is by using a flag
ex:
$b = false;
foreach( ...) {
if(!$b) { //edited for accuracy
$b = true;
continue;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With