将PHP key =>值转换为子数组:[key,value]

时间:2017-05-28 08:30:47

标签: php arrays json

我有以下数据:

Array ( [one] => this [two] => this2 )

我要将其转换为json类型,如下所示:

data:{[one,this],[two,this2]}

如何以有效的方式解决这个问题?

编辑: 我尝试了很多东西这是我需要使数据表兼容的实际数据:

{"draw":0,"recordsTotal":null,"recordsFiltered":null,"data":‌​[[{"first":[""],"sec‌​ond":[""],"third":["‌​"],"fourth":[""],"fi‌​fth":[""],"sixth":["‌​value"]}]]} 

因为这里的数据是key =>值形式json与数据表不兼容(PHP)

1 个答案:

答案 0 :(得分:1)

您可以使用array_maparray_keys

$result = array_map(null, array_keys($array), $array);

$json = json_encode($result);

这是working demo