首页 > 解决方案 > 列出来自数组的信息 (php)

问题描述

我已经通过 CURL 连接到一个 API,我得到了下面返回给我的内容。

我有点失落。但是我将如何在 PHP 的帮助下提取和显示信息,使其看起来像:

2018-10-26 - 28.46 美元

2018-10-27 - 25.70 美元

2018-10-28 - 29.07 美元

非常感谢您的帮助!/马库斯

{"options":{"ranking_metric":"paid_impressions","time_interval":"day","report_type":"time","filters":{"pid":"2759"},"data_source":"detailed","format":"json","end_date":"2018-10-28 23:59","columns":["paid_impressions","revenue"],"time_zone":"UTC","start_date":"2018-10-26 00:00"},"sql":"\n SELECT\n '',\n FIRST(CONCAT('',STRING(''))) AS _combined_val,\n SUM(if(media_tbl.mtid = 3, imps, 0)) as paid_impressions,SUM(pub_rev) as revenue,\n SUM(paid_impressions) OVER(PARTITION BY _combined_val) ranking_col,\n DENSE_RANK() OVER (ORDER BY ranking_col DESC) rank,\n STRFTIME_UTC_USEC(UTC_USEC_TO_DAY(timestamp +(7*1000*1000*60*60)),'%F %R') as timestamp\n FROM\n\n (SELECT * from TABLE_DATE_RANGE(counts.hourly_custom_cust1_, DATE_ADD(TIMESTAMP('2018-10-26 00:00'),-(7),'HOUR'), DATE_ADD(TIMESTAMP('2018-10-28 23:59'),7,'HOUR'))) as tbl\n\n LEFT JOIN (select sid as _sid, pid FROM counts.udm_synchronize_table_site_tbl) as site_tbl\n ON tbl.sid = site_tbl._sid\n\n LEFT JOIN (select mid as _mid, aid, tid, mtid FROM counts.udm_synchronize_table_media_tbl) as media_tbl\n ON tbl.mid = media_tbl._mid\n\n WHERE 1=1 AND site_tbl.pid IN (2759) AND timestamp >= DATE_ADD(TIMESTAMP('2018-10-26 00:00'),-(7),'HOUR') AND timestamp <= DATE_ADD(TIMESTAMP('2018-10-28 23:59'),-(7),'HOUR')\n GROUP BY timestamp,\n ORDER BY timestamp,rank,","api_url":"http://udmserve.com/udm/radalytics_api.cpx?action=report&api_key=xxxx&api_key=xxxx","time":1540989662,"rows":[{"paid_impressions":"18136","timestamp":"2018-10-26 00:00","_combined_val":"","ranking_col":"49046","revenue":"28.461629999999985","rank":"1","f0_":""},{"paid_impressions":"14432","timestamp":"2018-10-27 00:00","_combined_val":"","ranking_col":"49046","revenue":"25.707970000000017","rank":"1","f0_":""},{"paid_impressions":"16478","timestamp":"2018-10-28 00:00","_combined_val":"","ranking_col":"49046","revenue":"29.07676000000002","rank":"1","f0_":""}]}

标签: phphtmlarrayscurl

解决方案


您需要json_decode()卷曲响应并申请foreach()以获得所需的结果

$array = json_decode($curl_response,true);
foreach($array['rows'] as $arr){
  echo explode(' ',$arr['timestamp'])[0].'-'.number_format((float)$arr['revenue'], 2, '.', '').' USD'.PHP_EOL;
}

https://3v4l.org/eUavL


推荐阅读