我有这个PHP代码
$RTPerDate['revenue'][$DateGroupped['date']] += $telco['revenue'];
$RTPerDate['traffics'][$DateGroupped['date']] += $telco['traffics'];
哪个产生这个数组
Array(
[revenue] => Array
(
[2015-10-01] => 166600
[2015-10-02] => 578300
)
[traffics] => Array
(
[2015-10-01] => 167
[2015-10-02] => 576
)
我想让数组看起来像这样
Array(
[0] => Array
(
[revenue] => 166600
[traffics] => 167
[date] => 2015-10-01
)
[1] => Array
(
[revenue] => 578300
[traffics] => 576
[date] => 2015-10-02
)
感谢任何帮助。感谢
答案 0 :(得分:0)
修改强>
您是否意味着您希望按日期编制索引?
$RTPerDate[$DateGroupped['date']]['revenue'] += $telco['revenue'];
$RTPerDate[$DateGroupped['date']]['traffics'] += $telco['traffics'];
Array(
[2015-10-01] => Array
(
[revenue] => 166600
[traffics] => 578300
)
[2015-10-02] => Array
(
[revenue] => 167
[traffics] => 576
)
初步回答
这样的东西?
$RTPerDate[0]['revenue'] += $telco['revenue'];
$RTPerDate[0]['traffics'] += $telco['traffics'];
$RTPerDate[0]['date'] = $DateGroupped['date'];
$RTPerDate[1]['revenue'] += $telco['revenue'];
$RTPerDate[1]['traffics'] += $telco['traffics'];
$RTPerDate[1]['date'] = $DateGroupped['date'];
答案 1 :(得分:0)
试试这个
$field['revenue'][$DateGroupped['date']] += $telco['revenue'];
$field['traffics'][$DateGroupped['date']] += $telco['traffics'];
$RTPerDate[]['revenue'] = $field['revenue'][$DateGroupped['date']];
$RTPerDate[]['traffics'] = $field['traffics'][$DateGroupped['date']];
$RTPerDate[]['date'] = $DateGroupped['date'];
var_dump($ RTPerDate)查看格式化数组。
答案 2 :(得分:0)
谢谢大家,我做了一些小修改,所以像这样的代码
$RTPerDate[$DateGroupped['date']]['revenue'] += $telco['TheRevenue'];
$RTPerDate[$DateGroupped['date']]['traffics'] += $telco['TheTraffics'];
$RTPerDate[$DateGroupped['date']]['date'] = $DateGroupped['date'];
因此数组变得像这样
Array (
[2015-10-02] => Array
(
[revenue] => 578300
[traffics] => 576
[date] => 2015-10-02
)
[2015-10-03] => Array
(
[revenue] => 12825
[traffics] => 13
[date] => 2015-10-03
)
)