PHP: Convert array to JSON

后端 未结 1 1141
执念已碎
执念已碎 2020-12-21 14:52

myArray is:

Array
(
    [1] => 0
    [2] => 11970.99
    [3] => 2888
    [4] => 0
    [5] => 1500
    [6] => 0
    [7] => 0
    [8] =>         


        
1条回答
  •  Happy的楠姐
    2020-12-21 15:34

    Your issue is non-sequencial indexes.
    Php array must have indexes 0..array.length-1 to be encoded to JSON array.

    You can reset array keys with array_values:

    echo json_encode(array(
      array(name=> 'Recebimentos', data=>array_values($myArray)),
    ));
    

    0 讨论(0)
提交回复
热议问题