简体   繁体   English

如何替换foreach语句PHP

[英]how to alternate foreach statements PHP

How do I alternate these foreach statements in the sense that after one result of the first foreach statement is echoed one result from the second foreach statement will be echoed? 从第一个foreach语句的一个结果被回显后,我该如何替换这些foreach语句? Here are the two foreach statements. 这是两个foreach语句。

 foreach($anchors as $a) {
    $text = $a->nodeValue;
    $href = $a->getAttribute('href');
$i++;

if ($i > 16) {
    if (strpos($text, "by owner") === false) {
     if (strpos($text, "map") === false) {


          echo "<a href =' ".$href." '>".$text."</a><br/>";


     }
    }
  }

  }


foreach($span as $s) {
echo "<br>".$s->nodeValue."<br>" ;

}

Literally you cannot "merge" two foreach statements, but you can use each() function as workaround. 从字面上看,您不能“合并”两个foreach语句,但是可以将each()函数用作解决方法。 Place this somewhere in first cycle: 将其放置在第一个周期的某个位置:

list(,$s) = each($span);
echo "<br>".$s->nodeValue."<br>" ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM