亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 如果變量 = a 而不是 = b

PHP 如果變量 = a 而不是 = b

PHP
慕萊塢森 2023-05-12 15:52:36
PHP 7.3.18MySQL 5.7.30這是相關的代碼,它立即失敗,所以我很感激它被糾正。第一個“如果”沒問題,但問題出在第二個和第三個。$targetcatid2、$targetcatid3、$targetweight2、$targetweight3 已正確聲明。目的是如果產品屬于 Category2 而不是 Category3,則重量將變為 Weight2,反之亦然。$row2=mysqli_fetch_array($select2);if($row2['category_id']== $targetcatid){    $row['product_weight']= $targetweight;}if($row2['category_id']== $targetcatid2 && !== $targetcatid3){    $row['product_weight']= $targetweight2;}if($row2['category_id']== $targetcatid3 && !== $targetcatid2){    $row['product_weight']= $targetweight3;}我最近的努力是:如果($row2['category_id']== $targetcatid){ $row['product_weight']= $targetweight; }如果($row2['category_id']== $targetcatid2 && $row2['category_id']!== $targetcatid3){ $row['product_weight']= $targetweight2; }elseif($row2['category_id']== $targetcatid3 && $row2['category_id']!== $targetcatid2){ $row['product_weight']= $targetweight3; }elseif($row2['category_id']== $targetcatid2 && $row2['category_id']== $targetcatid3){ $row['product_weight']= $targetweight3; }我發現新條件不起作用,即使是單獨使用也是如此。但是不明白為什么:elseif($row2['category_id'] == $targetcatid2 && $row2['category_id'] == $targetcatid3){ $row['product_weight'] = $targetweight3; }
查看完整描述

1 回答

?
HUX布斯

TA貢獻1876條經驗 獲得超6個贊

您沒有正確理解 && 運算符。

而不是這個

if($row2['category_id']== $targetcatid2 && !== $targetcatid3){

您應該分別比較條件。

if($row2['category_id']== $targetcatid2 && $row2['category_id'] !== $targetcatid3){


查看完整回答
反對 回復 2023-05-12
  • 1 回答
  • 0 關注
  • 142 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號