从值创建多维数组

时间:2015-10-29 07:40:32

标签: php arrays json

我想从下面的数字创建MD数组,以发送为JSON

OrderStatus  Counts
Shipped      3

Pending      5

最终输出应为,

[{order_status: "Shipped", Counts: 3}, {order_status: "Pending", Counts: 5} ]

目前我只能发送一行

$orderTable[] = array(
                'order_status' => 'Shipped',
                'Counts' => 3);

如何将两个值作为Json数组发送?

1 个答案:

答案 0 :(得分:3)

您可以像这样创建数组:

$orderTable = [ 
   [
      'order_status' => 'Shipped',
      'Counts' => 3
   ],
   [
      'order_status' => 'Pending',
      'Counts' => 5
   ]
];

$json = json_encode($orderTable);