php 生成缓存数组,简单的PHP缓存 - 可以将数据存储在数组中,但是如何从数组缓存中检索项目?...

$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);它打印什么? –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值