0
它只能檢測到第一個條件,任何其他條件都不會工作。 xpath是正確的。如果我沒有循環,它會工作。我在這裏做錯了什麼?循環遍歷isEmpty
$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次......你想要做什麼? – elclanrs
如果第一個else如果是空的,那就去其他的if – CodeGuru
如果第一個是空的,所有其他的都是空的,你一遍又一遍地測試同樣的東西......我不明白你的邏輯是什麼。 – elclanrs