1 回答
TA贡献1802条经验 获得超10个赞
您可以使用布尔变量来指示您是否以第一种方式找到了描述,如果没有,则以第二种方式找到它:
$descriptionFound = false;
foreach(Feed('https://www.vegvesen.no/trafikk/xml/savedsearch.rss?id=601') as $f) {
if (strpos($f->title, $title) !== false){
$pos = $f->children('georss', true)->children('gml', true)->children('gml', true);
list($number1, $number2) = explode(' ', $pos);
if (
$number1 > 59.417104 && $number1 < 60.089568
&& $number2 > 5.115812 && $number2 < 7.811784
) {
$descriptionFound = true;
echo $f->description . "<br>";
}
}
}
if (!$descriptionFound) {
foreach(Feed('https://www.vegvesen.no/trafikk/xml/savedsearch.rss?id=604') as $f) {
if (strpos($f->title, $title) !== false){
echo $f->description . "<br>";
}
}
}
同样,您可以在检查各种方法时存储描述,然后在最后输出值:
$description = '';
foreach(Feed('https://www.vegvesen.no/trafikk/xml/savedsearch.rss?id=601') as $f) {
if (strpos($f->title, $title) !== false){
$pos = $f->children('georss', true)->children('gml', true)->children('gml', true);
list($number1, $number2) = explode(' ', $pos);
if (
$number1 > 59.417104 && $number1 < 60.089568
&& $number2 > 5.115812 && $number2 < 7.811784
) {
$description .= $f->description . "<br>";
}
}
}
if (!$description) { //this will be falsy if it's an empty string, so no need to do == ''
foreach(Feed('https://www.vegvesen.no/trafikk/xml/savedsearch.rss?id=604') as $f) {
if (strpos($f->title, $title) !== false){
$description .= $f->description . "<br>";
}
}
}
echo $description;
要么会给你相同的代码流和最终结果。
- 1 回答
- 0 关注
- 108 浏览
添加回答
举报