我有一个 PHP 中的多维数组:
Array
(
[1] => Array
(
[19] => Array
(
[type] => 2
)
[6] => Array
(
[type] => 4
)
[12] => Array
(
[type] => 3
)
)
)
当我在JavaScript中使用以下代码对此数组进行json编码:
var jsonArray = <?php echo json_encode($above_array); ?>;
我理解为:
Object
(
[1] => Object
(
[6] => Object
(
[type] => 2
)
[12] => Object
(
[type] => 4
)
[19] => Object
(
[type] => 3
)
)
)
我希望保留第一排序而不是按id保留第二排序。
[[19, {type: 2}], [9, { type: 2}], [6, {type: 4}], [12, {type: 3}]]
,也就是一个包含两个元素的嵌套数组,其中每个嵌套数组都包含“索引”和type
对象。 - user229044