繁体   English   中英

php if语句只返回1st“if”

[英]php if statement only returns 1st “if”

我的php在某处的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;

$history_type = 'spent'必须是$history_type == 'spent'

Assigments总是返回assigment值。 $history_type = 'spent'返回'花费',这被解释为true

if一定要长相

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;

赋值运算符比较运算符

为了避免出现这种错误,你可以改变价值和变量的位置。

'spent' = $history_type - 永不工作'spent' == $history_type - 按预期工作

你在这里分配而不是比较:

 if ($history_type = 'spent'):

这就是为什么它总是具有'花费'的价值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM