關於運算子的有關問題。為毛這樣

來源:互聯網
上載者:User
關於運算子的問題。為毛這樣?
PHP code
if($item[$column_name] .$operation. $info)        {            echo $item[$column_name] .$operation. $info;echo '=====true';echo '
'; return true; }else{ echo $item[$column_name] .$operation. $info;echo '=====false';echo '
'; return false; }輸出:508205462=505765854=====true10>1234567=====true20<66666=====true解釋:$item[$column_name] 的結果就相當於運算子的第一個 ,$operation是運算子,$info是值,為什麼直接寫if(10>1234567)返回假,用程式運算出來全部為真??



------解決方案--------------------
因為有“.”,所以你那些變數當做字串串連起來了
如果想讓他們當做運算式運算,需用 eval 函數

eval('return '. $item[$column_name] .$operation. $info. ';')
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.