What is the best way to define a new multidimensional array with default key/value pairs?
I think it's best explained by code sample here:
$defaultOptions = ['foo' => 'bar', 'another' => 'value'];
$mdArray = [
'first' => [
'title' => 'I am first',
$defaultOptions,
],
'second' => [
'title' => 'I am second',
$defaultOptions
]
];
This produces:
Array
(
[first] => Array
(
[title] => I am first
[0] => Array
(
[foo] => bar
[another] => value )
)
[second] => Array
(
[title] => I am second
[0] => Array
(
[foo] => bar
[another] => value
)
)
)
I would like the 0
key to be omitted from $defaultOptions
in $mdArray
, so that key/value pair would be applied to the same level as where the $defaultOptions
is defined.
Is there a way to do it within array definition, or do I have to process this array later and append these $defaultOptions
?