I have the following array
:
$arrIni["ENV"]="US";
$arrIni["sap_db_server"] = "192.xxx.x.xx";
$arrIni["local_db_server"] = "localhost";
$arrIni["local_db_username"] = "root";
//Default settings
$arrIni["arrEnvSettings"]["UserTypeID"]=4;
$arrIni["arrEnvSettings"]["LocalizationID"]=1;
$arrIni["arrEnvSettings"]["LangLabels"] = array();
$arrIni["arrEnvSettings"]["pages"]["st1"]="st1.php";
$arrIni["arrEnvSettings"]["pages"]["st2"]="st2.php";
$arrIni["arrEnvSettings"]["pages"]["st3"]="st3.php";
I'm using the merge function with array $setParam
$setParam["arrEnvSettings"]["pages"]["st3"]="st3_V2.php";
as follows:
echo "<pre>";
print_r(array_merge($arrIni,$setParam));
echo "</pre>";
This is the result:
Array
(
[ENV] => US
[sap_db_server] => 192.xxx.x.xx
[local_db_server] => localhost
[local_db_username] => root
[arrEnvSettings] => Array
(
[pages] => Array
(
[st3] => st3_V2.php
)
)
)
This is the desired result:
Array
(
[ENV] => US
[sap_db_server] => 192.xxx.x.xx
[local_db_server] => localhost
[local_db_username] => root
[arrEnvSettings] => Array
(
[UserTypeID] => 4
[LocalizationID] => 1
[LangLabels] => Array
(
)
[pages] => Array
(
[st1] => st1.php
[st2] => st2.php
[st3] => st3_V2.php
)
)
)
I do not understand why the merge function is deleting the contents of the [arrEnvSettings]
array. According to the documentation it should only overwrite the [st3]
value from st3.php
to st3_V2.php
. "...Se os *arrays* dados têm as mesmas chaves string, então o último valor para uma chave irá sobrescrever o valor anterior ..."
.
What am I doing wrong?