I have some confusion about why the following code does not work:
$data_set = array();
for($i=1; $i<=3; $i++)
{
$data_val = array($i, $i*2);
$data_set[] = $data_val;
}
echo json_encode($data_set);
What I expect is something like
[ [1,2], [2,4], [3,6] ]
What I get is an empty string.
But, If I do this
$data_set = array();
for($i=1; $i<=3; $i++)
{
$data_val = array($i, $i*2);
$data_set[] = json_encode($data_val);
}
echo json_encode($data_set);
I get something like this:
[ "[1,2]", "[2,4]", "[3,6]" ]
So, it seems like deeper Arrays do not work. What am I missing?
[[1,2],[2,4],[3,6]]
– Drumbeg Jun 11 at 19:59var_dump($data_set);
instead? Your code works: 3v4l.org/AiL2U – Halcyon Jun 11 at 20:00