【问题标题】:Looping through isEmpty遍历 isEmpty
【发布时间】:2013-10-13 07:06:00
【问题描述】:

它只能检测第一个条件,if else 的任何东西都行不通。 xpath 是正确的。如果我在没有循环的情况下这样做,它将起作用。我在这里做错了什么吗?

$pricediscount = "";
$chinesename ="";


if (empty($pricediscount)){
        $pricediscount = (@$xpath->query("//*[@id='J_PromoPrice']/div/strong/text()")->item(0)->nodeValue);
    }elseif(empty($pricediscount)){
        $pricediscount = (@$xpath->query("//*[@id='J_StrPrice']/em[2]")->item(0)->nodeValue);
    }elseif(empty($pricediscount)){
        $pricediscount = (@$xpath->query("//*[@id='J_PromoBox']/strong")->item(0)->nodeValue);
    }elseif(empty($pricediscount)){
        $pricediscount = (@$xpath->query("//*[@id='J_StrPrice']")->item(0)->nodeValue);
    }else{
        $pricediscount = "NA";
    }

【问题讨论】:

  • 嗯,你正在测试相同的条件 3 次......你到底想做什么?
  • 如果第一个else if为空,则继续下一个else if
  • 如果第一个是空的,所有其他的也是空的,你一遍又一遍地测试同样的东西......我不明白你的逻辑是什么。
  • 如果第一个 xpath 查询不起作用,请尝试下一步。如果它有一些东西,它会用一些东西更新 $priceiscount。所以如果有东西不是空的,那就停下来
  • "//*[@id='J_StrPrice']" *************** 两者不同 *********** * @$xpath->query("//*[@id='J_PromoBox']/strong"

标签: php html loops for-loop


【解决方案1】:

您只运行第一个if 语句,因为它始终为真,因此不会评估else 块。尝试将elseifelse 语句更改为if

【讨论】:

    猜你喜欢
    • 2011-05-31
    • 2023-03-17
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 2018-07-15
    相关资源
    最近更新 更多