我的php在if語句的某處肯定是錯的。出於某種原因,它只會在數組中以「歷史類型」的形式返回「購買」,即使原始數據以其他方式顯示我也是如此。我做錯了什麼?php if語句只返回第一個「if」
$history = $api->get_wallet_history('USD');
$i = 0;
while ($i <= 9):
$history_date = $history[result][$i][Date];
//$history_date->format("m-d-y");
//print_r($history_date);
$history_type = $history[result][$i][Type];
if($history_type = 'spent'):
$history_type = 'Buy';
elseif($history_type = 'earned'):
$history_type = 'Sold';
elseif ($history_type = 'fee'):
$history_type = 'Fee';
else:
$history_type = 'Error';
endif;
//print_r($history_type);
$history_usd = $history[result][$i][Balance][value];
$history_btc = $history[result][$i][Trade][Amount][value];
$history_amt = $history[result][$i][Value][value];
echo '<tr><td>'.$history_type.'</td><td>'.$history_amt.'</td><td>'.$history_usd.'</td><td>'.$history_btc.'</td><td>'.$history_date.'</td></tr>';
$i++;
endwhile;
值請記住,比較字符串時,請使用'=='而不是'='。 PHP中的'='是賦值運算符。 – Ruly
爲什麼不使用'{}'... – aldanux
謝謝,即使在「If」語句中我也沒有意識到這是真的。 我還以爲==意思是「絕對等於」。即,如果($ history_type「絕對等於」「花」): 其現在已經很清楚。感謝大家的解釋。 –