PHP索引数组到关联JSON

Pyr*_*ite 3 php json

我有以下PHP数组:

array("Apple", "Pear", "Grape", "Orange")
Run Code Online (Sandbox Code Playgroud)

我想获得如下的JSON输出:

[[{"fruit":"Apple"}],[{"fruit":"Pear"}],[{"fruit":"Grape"}],[{"fruit":"Orange"}]]
Run Code Online (Sandbox Code Playgroud)

JSON让我困惑:(

编辑 对不起,输出中的最后两个应该是水果,我纠正了,对不起伙计们.

Ada*_*cki 5

如果您希望JSON输出看起来像这样,您应该将PHP值更改为如下所示:

array(array(array('fruit' => 'Apple')), array(array('fruit' => 'Pear')), array(array('fruit' => 'Grape')), array(array('fruit' => 'Orange')))
Run Code Online (Sandbox Code Playgroud)

然后将该数组传递给 json_encode()