如何提取信息并将true转换为1?

时间:2015-04-01 04:24:51

标签: php arrays string multidimensional-array

我收到了这段代码:

foreach($data['matches'] as $matches){
$win += $matches['participants'][0]['stats']['winner'];
if ($win == true){
$winner+= '1';
}
}

此代码从API中提取信息,我想要的是API中“值”的值是多少,所以我试图将“true”转换为1,但仍然无法正常工作。
在api中有8个“真实”,但当我试图打印$winner时,我只有2个。
该怎么做才能更正代码?

1 个答案:

答案 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++;
}
}