We have a multidimensional array that currently looks like this.
[totalsByYardHand] =>
[Jon Doe] =>
[Delivieries] => 6
[Pickups] => 5
[Errors] => 8
[Fred] =>
[Delivieries] => 6
[Pickups] => 5
[Errors] => 8
Since we are passing this array off to JavaScript and want to maintain the order we are needing this to be formatted correctly. We are wanting to take the array and format it as so.
Array
(
[totalsByYardHand] => Array
(
[0] => Array
(
[0] => Jon Doe
[1] => Array
(
[0] => Array
(
[0] => Deliveries
[1] => 6
)
[1] => Array
(
[0] => Pickup
[1] => 6
)
[2] => Array
(
[0] => Errors
[1] => 1
)
)
)
[1] => Array
(
[0] => Fred
[1] => Array
(
[0] => Array
(
[0] => Deliveries
[1] => 6
)
[1] => Array
(
[0] => Pickup
[1] => 6
)
[2] => Array
(
[0] => Errors
[1] => 1
)
)
)
)
)
The closest attempt we made was a recursive function like so, but cannot figure out how to add the array keys from the original array into the newly formatted array.
function array_values_recursive($array)
{
$array = array_values($array);
for ($i = 0, $n = count($array); $i < $n; $i++) {
$element = $array[$i];
if (is_array($element)) {
$array[$i] = $this->array_values_recursive($element);
}
}
return $array;
}
formatted correctlyYour second example is not correctly formatted. Lookup this part[0] => Jon Doeand the next line[0] =>i thing this wont work