在 PHP 数组中的每个值后添加逗号

Add commas after each value in PHP Array

我正在尝试将每个比赛 ID 存储在以下函数中:

function getSoccerByCountry($appKey, $sessionToken, $country, $competitionid)
{
    $jsonResponse = sportsApingRequest($appKey, $sessionToken, 'listMarketCatalogue', '{"filter":{
                "eventTypeIds": [
                    "1"
                ],"competitionIds":["' . $competitionid . '"],"marketTypeCodes":["MATCH_ODDS"],"marketCountries":["' . $country . '"],"inPlayOnly": true
            },
            "maxResults": "200",
            "marketProjection": [
                "COMPETITION",
                "EVENT",
                "EVENT_TYPE",
                "RUNNER_DESCRIPTION",
                "RUNNER_METADATA",
                "MARKET_START_TIME"
            ]
        },
        "id": 1}
]');

我为每个循环创建了这个,它循环数组的每个键值并只获取传递给 getSoccerByCountry 函数的比赛 ID。

foreach ($getSoccerComp as $key1)
{           
    $getSoccerCountry = getSoccerByCountry($appKey, $sessionToken, $countrycode, $key1->competition->id);
}

尽管所有比赛 ID 都作为一个整数传递,但我希望它们以逗号分隔传递。

Screenshot

是这样的吗?

foreach ($getSoccerComp as $key1){           
    $ids[] = $key1->competition->id;
}

getSoccerByCountry($appKey, $sessionToken, $countrycode, implode(',', $ids));

因为除了用值 null 一遍又一遍地重写变量外,你没有对 $getSoccerCountry 做任何事情,所以我删除了过时的代码。