我收到了这段代码:
foreach($data['matches'] as $matches){
$win += $matches['participants'][0]['stats']['winner'];
if ($win == true){
$winner+= '1';
}
}
此代码从API中提取信息,我想要的是API中“值”的值是多少,所以我试图将“true”转换为1,但仍然无法正常工作。
在api中有8个“真实”,但当我试图打印$winner
时,我只有2个。
该怎么做才能更正代码?
答案 0 :(得分:0)
只需$win = $matches['participants'][0]['stats']['winner'];
,然后$win
等于true
增量$winner
。
$winner = 0;
foreach($data['matches'] as $matches){
$win = $matches['participants'][0]['stats']['winner'];
if ($win == true) {
$winner++;
}
}