我有这个php索引数组。
array(
(int) 0 => array(
'id' => '4',
'good_time' => '2014-05-01 03:36:00',
),
(int) 1 => array(
'id' => '5',
'good_time' => '2014-06-27 11:14:00',
),
(int) 2 => array(
'id' => '6',
'good_time' => '2014-06-27 11:20:24'
)
我想在前面添加一个键,这样当我在json中打印它时,它看起来更有意义。
'Time' => array(
(int) 0 => array(
'id' => '4',
'good_time' => '2014-05-01 03:36:00',
),
(int) 1 => array(
'id' => '5',
'good_time' => '2014-06-27 11:14:00',
),
(int) 2 => array(
'id' => '6',
'good_time' => '2014-06-27 11:20:24'
)
)
如何在php中完成?
答案 0 :(得分:4)
这很容易:
$newArray['Time'] = $otherArray;
或
$newArray = array('Time' => $otherArray); // now you can add other keys to $newArray
答案 1 :(得分:0)
假设您的数组存储在$a
变量中。你可以做到
$a = array('Time' => $a);