PHP / Jquery multidimensional array
Solution:
You were close, you just have to make two corrections:
- there's an array level missing under
series
value
andmeta
values shouldn't be arrays
Your array should look like this before encoding:
$return = array(
"labels" => [1,2,3],
"series" => [ // numeric array, will be encoded as array
[ // also numeric array, will be encoded as array (this one was added)
array( // associative array, will be encoded as object
"meta" => 'description', // value not placed in an array
"value" => 1, // value not placed in an array
),
],
],
);
Answer
Solution:
You could try this...
<?php
$return = array(
"labels" => [1,2,3],
"series" => [
array(
(object)[
"meta" => 'description',
"value" => 1,
]
),
],
);
echo '<pre>';
print_r($return);
print_r(json_encode($return));
echo '</pre>';
Source