I'm trying to call methods while building an array. I am building a fairly large config array which contains many re usable blocks.
This is the array that I'd like to get:
array(
"masterKey" => array(
"myKey" => array(
"valueField" => "hi"
),
"anotherKey" => array(
"valueField" => "hi again"
)
....
)
);
This is how I'd like to generate it:
array(
"masterKey" => array(
self::getValueField("myKey", "hi"),
self::getValueField("anotherKey", "hi again"),
...
)
);
private static function getValueField($key, $value)
{
return array($key =>
"valueField" => $value
);
}
But this gives me
array(
"masterKey" => array(
[0] => array(
"myKey" => array(
"valueField" => "hi"
)
),
[1] => array(
"anotherKey" => array(
"valueField => "hi again"
)
)
)
);
Instead of constructing the
"masterKey"
field as a literal, merge the arrays returned byself::getValueField
: