$c->setCache("$appid")
->store("$appid", array(
'name' => "$gname",
'price' => "$price",
'logo' => "$glogo",
'link' => "$glink"
)
);
$gcache = $c->retrieve("$appid");
$cprice = $gcache->price; //not sure how to retrieve the price value only
以下是完整的代码,我似乎无法从存储阵列得到的价格:
require_once 'cache.class.php';
// Setup 'default' Cache
$c = new Cache();
$glist = "http://steamcommunity.com/id/aksn1p3r/games?tab=all&xml=1";
$gxml = simplexml_load_file($glist);
$tprice = 0;
$i = 0; //just used to exit loop after 2 executions
foreach($gxml->games->game as $game) {
if($i >= 2) {
break;
}
$appid = $game->appID;
$glink = $game->storeLink;
$gname = $game->name;
$glogo = $game->logo;
$gjson = 'http://store.steampowered.com/api/appdetails/?appids=' . $appid;
$fgc = file_get_contents($gjson);
$jd = json_decode($fgc, true);
$gdata = $jd[intval($appid)]['data']; //$appid needs to be integer here, not string
$gdesc = $gdata['about_the_game'];
$gprice = $gdata['price_overview']['final'];
$price = number_format($gprice/100, 2);
$c->setCache("$appid")
->store("$appid", array(
'name' => "$gname",
'price' => "$price",
'logo' => "$glogo",
'link' => "$glink"
)
);
// this part is where I dont understand how to get the price I stored.
$cprice = $c->retrieve["$appid"]['price'];
$tprice += $cprice;
$i++;
}
echo 'Total games: ' .$i. '
';
echo 'Total Price: ' .$tprice;
?>
2013-05-29
A K
+1
这将有利于你和我们,如果你能告诉我们你当前的工作代码..你不能找回什么,它是嵌套在等 –
+0
你好,是的,对不起,我是编辑。 –
+0
如果你做了一个var_dump($ cprice);它打印什么? –