我的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“绝对等于”“花”): 其现在已经很清楚。感谢大家的解释。 –