Reputation: 751
How can I indent arrays in PHP?
Say we have the following array
[Array] (
[red] => 10
[green] => 20
[blue] => 30
)
How can I indent it in one level, so that I have this at the end
[Array] (
Colors => [Array] (
[red] => 10
[green] => 20
[blue] => 30
)
)
Upvotes: 1
Views: 1644
Reputation: 401032
Basically, you want your first array to become embeded in another one ?
If so, what about :
$newArray = array(
'Colors' => $yourOldArray
);
Of course, $yourOldArray
is the variable that contains your old array ;-)
Or you can replace the $yourOldArray
part by the content of that old array itself.
Of, if the new array already exists, and you just want to add a sub-item to it :
$newArray['Colors'] = $yourOldArray;
Upvotes: 3