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

How to extract information and transform true to 1?

我得到了这个代码:

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

此代码从 API 中提取信息,我想要的是 "true" 在 API 中的值是多少,所以我尝试转换 "true" 到 1,但仍然无法正常工作。
在 api 中有 8 个 "true" 但是当我尝试打印 $winner 时我只得到了 2 个。
请如何更正代码?

只要$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++;
}
}