怎么可能读取特定项目的编号呢?例如:此id中有多少项可用?:927007517
代码:
<?php
$content = file_get_contents('http://steamcommunity.com/profiles/76561198131798299/inventory/json/730/2');
$result = json_decode($content);
if($result->success !== true) {
echo 'Nicht erfolgreich! :(';
return;
}
foreach($result->rgInventory AS $item) {
echo $item->classid.'<br />';
}
?>
输出:http://csgo.square7.ch/csgo-master/api.php
谢谢。致以最诚意的问候
发布于 2015-12-04 18:17:18
您可以使用array_count_values
函数计算一个值返回的次数。这将创建一个以id作为键,count作为值的新数组。
如下所示:
$count = array_count_values($result->rgInventory);
echo $count['927007517'] // Will echo the number of times this id is found
发布于 2015-12-04 18:35:56
你不能使用array_count_values,但你可以写简单的计数器
$content = file_get_contents('http://steamcommunity.com/profiles/76561198131798299/inventory/json/730/2');
$result = json_decode($content);
if($result->success !== true) {
echo 'Nicht erfolgreich! :(';
return;
}
$count = [];
foreach($result->rgInventory as $item) {
array_key_exists($item->classid, $count) ? ++$count[$item->classid] : ($count[$item->classid] = 0);
}
echo $count[927007517];
https://stackoverflow.com/questions/34085725
复制相似问题