Reputation: 408
my main array name is $constant...
$constants = array(
'residential' => array(
"flat" => "Flat", "swimming_pool" => "Swimming pool",
"hall" => "Hall", "garden" => "Garden", "clubhouse" => "Clubhouse"
),'commercial' => array(
"shop" => "Shop", "office" => "Office"
),);
i can merge this array using array_merge like
$result = array_merge($constants['residential'],$constants['commercial']);
but i want to merge this array where i declare that array like..
$constants = array(
'residential' => array(
"flat" => "Flat", "swimming_pool" => "Swimming pool",
"hall" => "Hall", "garden" => "Garden", "clubhouse" => "Clubhouse"
),'commercial' => array(
"shop" => "Shop", "office" => "Office"
),
'test' => array_merge('residential','commercial'));
is that possible please help.....
Upvotes: 0
Views: 232
Reputation: 3551
No, this is not possible - you can't use values from the array that is just in the process of being declared, so the way to do it is similar to your first code snippet:
$constants = array(
'society_types' => array(
"residential"=>"Residential", "commercial"=>"Commercial", "resicumcomm" => "Residential cum Commercial"
),
'residential' => array(
"flat" => "Flat", "swimming_pool" => "Swimming pool", "hall" => "Hall", "garden" => "Garden", "clubhouse" => "Clubhouse"
)
);
$constants['test'] = array_merge($constants['society_types'], $constants['residential']);
Upvotes: 1