0

我正在尝试将此脚本从查找一组变量(例如(playtime_forever))转换为查找另一个变量(例如(backpack_value)

if (!empty($data->response->games)) {
  foreach ($data->response->games as $game) {   
    if ($game->appid == $game_id) { 
      $playtime = $game->playtime_forever;
      if (($playtime < 5940) && ($playtime > 1)) {
        $fh = fopen("final.".$timestamp.".txt", 'a') or die("Can't open file");
...

它最初解析的页面看起来像这样 http://pastebin.com/rnnCsijd

但现在将是这个。从这里拉 http://backpack.tf/api/IGetUsers/v2/?&steamids=76561197992146126&format=json%27

{
    "response": {
        "success": 1,
        "current_time": 1369669066,
        "players": {
            "0": {
                "steamid": "76561197992146126",
                "success": 1,
                "backpack_value": 36412.71,
                "backpack_update": 1369630863,
                "name": ":HIT: Bobo the Monkey Boy",
                "notifications": 0
            }
        }
    }
}

一个小改动,但我无法让脚本做我想做的事。如果您能解释如何进行此操作及其背后的步骤,那就太好了。我已经尝试了一段时间,但我无法完成脚本

4

1 回答 1

1

要根据您的评论获取配置文件,请使用以下代码:

$profiles = array(); //init array so we can use $profiles[] later
$limitValue = 1000;  //Limit value of backpack_value

foreach($data->response->players as $player) { // Loop thrugh all the players
  if ($player->backpack_value < $limitValue) { // Check the backpack_value
    $profiles[] = $player; // Assign the required players to a new array
  }
}
var_dump($profiles); // Dump the array to browser for debugning
于 2013-05-27T17:57:43.720 回答