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

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

為什么 if 不進行比較?

為什么 if 不進行比較?

PHP
眼眸繁星 2022-05-27 13:21:28
我試圖通過 if 語句比較兩個數字,但它不起作用。一個數字來自 .txt 文件中的數據庫。這是數字來自的數據庫:Number of registrations: 6450|name|surname|email|1241241261|name|surname|email|07802634202 這是腳本:$phone = "07802634202";// Get th file from the database and convert it in an array$database = file("database.txt", FILE_SKIP_EMPTY_LINES);// Get the lenght of the database "Rows"$database_length = count($database);// Transform  in an array the string inside each row and save them in a variable for($a = 1; $a < $database_length; $a++) {  $data[$a] = explode("|", $database[$a]);}// Check if the last variable 'Number' in a row is equal to $phone foreach($data as $key => $val) {  echo "Database val: " . $val[4];  echo "Phone val: " . $phone;  // If it's equal print yep otherwise nope  if ($val[4] == $phone) {     echo "\n yep \n";   } else {     echo "\n nope \n";  }}這是控制臺打印的內容:Database val: 12412412                                                                                                                                          Phone val: 07802634202                                                                                                                                           nope                                                                                                                                                           Database val: 07802634202                                                                                                                                       Phone val: 07802634202                                                                                                                                           nope    如果有不清楚的地方,請告訴我。我已經嘗試了一切,但沒有任何結果。謝謝你的幫助 :)
查看完整描述

1 回答

?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

由于您的數據來自各種來源,因此始終值得trim填寫字段以確保刪除任何前導或尾隨空格。

if (trim($val[4]) == trim($phone)) {...}

只是一個小小的補充,值得添加FILE_IGNORE_NEW_LINES到調用,file()否則你將在行尾以新行結束。


查看完整回答
反對 回復 2022-05-27
  • 1 回答
  • 0 關注
  • 169 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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