列出来自数组的信息 (php)

Posted

技术标签:

【中文标题】列出来自数组的信息 (php)【英文标题】:Listing information from an Array (php) 【发布时间】:2019-04-04 15:21:08 【问题描述】:

我已经通过 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_":""]

【问题讨论】:

你试过了吗? 您到底尝试了什么?这些价值观从何而来? “美元”从何而来? 【参考方案1】:

您需要json_decode() curl 响应并应用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

【讨论】:

非常感谢!这太棒了,效果很好:) 再问一个问题。我怎么能很容易地列出下面的总数?谢谢!!

以上是关于列出来自数组的信息 (php)的主要内容,如果未能解决你的问题,请参考以下文章

用来自 php 的数据填充 flash 中的数组

来自 fetch 的 PHP 回显数组

要列出的 PHP 数组

如何从 php 中列出的数组中获取 xml 输出?

php wordpress:列出数组中所有已安装的插件

在具有特定 ID 的 div 中插入来自 PHP 的值