JSON编码相乘数组作为单个阵列(JSON encode multiplies arrays as

2019-10-18 05:39发布

$array = array(
    $this->_order->revenue_seller($value,$from,$to),
    $this->_order->refund_seller($value,$from,$to),
    $this->_order->customers_seller($value,$from,$to),
    $this->_order->sales_seller($value,$from,$to)
);
$this->response($array,200);

我想数据被显示为一个单一的阵列,但如我们所看到的,输出是开始显示为数组的数组:

[
    [
        {
            "min_amount":"2.00",
            "max_amount":"2.00",
            "avg_amount":"2.000000",
            "total_revenue":"2.00"
        }
    ],
    [
        {
            "total_refund_amount":"1.00"
        }
    ],
    [
        {
            "created_at":"2013-03-24 15:04:35"
        }
    ],
    [
        {
            "quantity":"1"
        }
    ]
]

我怎样才能使数据显示为一个单一的阵列?

像这样:

[
{
"day":"2013-03-19",
"min_amount":"0.00",
"max_amount":"0.00",
"avg_amount":"0.000000",
"total_revenue":"0.00",
"quantity" : "1",
"total_refunded_amount":null,
"created_at":"2013-03-24 15:04:35"   
}]

Answer 1:

如果您收到的所有四个功能阵列回报不是使用array_merge为,

$array = array_merge($this->_order->revenue_seller($value,$from,$to),
                     $this->_order-refund_seller($value,$from,$to),
                     $this->_order->customers_seller($value,$from,$to),
                     $this-_order->sales_seller($value,$from,$to));
$this->response($array,200);

DEMO。



文章来源: JSON encode multiplies arrays as single array