Php 在foreach循环中创建具有不同名称的变量 $id='7656119803641106'; $key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $link2=文件\u获取\u内容('http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=“.$key.&streamid=”.$id.&relationship=friend'); $myarray2=json_decode($link2,true); foreach($type为myarray2['friendslist']['friends']{ echo“id:”.$type['streamid']; [将此$type['streamid']保存到一个var中,然后再次执行foreach并将下一个变量保存到另一个变量] }

Php 在foreach循环中创建具有不同名称的变量 $id='7656119803641106'; $key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $link2=文件\u获取\u内容('http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=“.$key.&streamid=”.$id.&relationship=friend'); $myarray2=json_decode($link2,true); foreach($type为myarray2['friendslist']['friends']{ echo“id:”.$type['streamid']; [将此$type['streamid']保存到一个var中,然后再次执行foreach并将下一个变量保存到另一个变量] },php,api,steam,Php,Api,Steam,如何保存foreach输出到多个变量的输出?var1、var2、var3等,直到阵列不再输出任何内容 我想做的是,这个脚本将获取我所有朋友在steam上的社区ID,然后我将获取这些ID并通过另一个api调用运行它们,该api调用将获取我的朋友在过去两周内玩过某个游戏的次数。因此,我所需要的就是如何保存api输出的所有社区ID,并将它们全部放在一个单独的变量中 将这些SteamID保存到数组中 $id = '76561198036414106'; $key = 'xxxxxxxxxxxxxxxxx

如何保存foreach输出到多个变量的输出?var1、var2、var3等,直到阵列不再输出任何内容


我想做的是,这个脚本将获取我所有朋友在steam上的社区ID,然后我将获取这些ID并通过另一个api调用运行它们,该api调用将获取我的朋友在过去两周内玩过某个游戏的次数。因此,我所需要的就是如何保存api输出的所有社区ID,并将它们全部放在一个单独的变量中

将这些SteamID保存到数组中

$id = '76561198036414106';
$key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$link2 = file_get_contents('http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=' . $key . '&steamid=' . $id . '&relationship=friend');
    $myarray2 = json_decode($link2, true);

    foreach ($myarray2['friendslist']['friends'] as $type) {
           echo "<br>id: " . $type['steamid'];
           [save this $type['steamid'] into a var, then do a foreach again and save down the next to another variable]
        }
此时,您可以使用另一个
foreach
调用SteamID

$steamids = array();
foreach ( ... )
{
    array_push($steamids, $type['steamid']);
}
foreach($steamids as $steamid)
{
    // Call your API
}