douzhen9428 2016-01-31 17:22
浏览 35
已采纳

计算数组中的项目数

This is my code. I am trying to get number of trade offers through steam API. I can get an array but i dont know how to count number of items from this array

<?php 
$json_url = "http://api.steampowered.com/IEconService/GetTradeOffers/v0001/?key=KEY&get_received_offers=1&active_only=1";
$json = file_get_contents($json_url);
$data = json_decode($json, TRUE);
echo '<pre>' . print_r($data, true) . '</pre>';

How can I get the number of [trade_offers_recived] ? Currently there are 2 trade offers recived (0 and 1)

  • 写回答

3条回答 默认 最新

  • dousong8187 2016-01-31 17:35
    关注

    Your $data array contains "response" arrays, and these "trade_offers_received" arrays. So try this:

    $numtradeoffers = count($data['response']['trade_offers_received']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi