Convert PHP array to chart.js compatible data

๐Ÿ‘:0

You could create an array with key โ€œdataโ€ and another array as the value;

$myArray = ["data" => [1, 2, 3]];
echo json_encode($myArray);

Output

{"data":[1,2,3]}

Or put the values between quotes

$myArray = ["data" => ["1", "2", "3"]];

Output

{"data":["1","2","3"]}

๐Ÿ‘:-1

Not sure completely understood the problem. But if you want to convert values of php array to a json you can do something like that:
json_encode(array_values($myArray));

Leave a comment