I am trying to convert an array to nested array by its items. My array contains mainly 10 items and they have key and value.Keys have [] brackets..My primary array is:
$data = Array
(
[4/3/20] => 61
[4/4/20] => 70
[4/5/20] => 88
[4/6/20] => 123
[4/7/20] => 164
[4/8/20] => 218
[4/9/20] => 330
[4/10/20] => 424
[4/11/20] => 482
[4/12/20] => 621
)
My end result is:
Array
(
[0] => Array
(
[x] =>
[y] => 61
)
[1] => Array
(
[x] =>
[y] => 70
)
.....
[8] => Array
(
[x] =>
[y] => 482
)
[9] => Array
(
[x] =>
[y] => 621
)
)
But x is missing here.. I am using this function
foreach ($data as $key => $value) {
$arr = array(
'x' => $Key,
'y' => $value,
);
array_push($dataset, $arr);
}
return $dataset;
I have selected keys from its array. Am i missing something here..??