Test code:
$ A1 = array ('dbhost' => 'localhost', 'dbname' => 'nextblog ', 'dbport' => 3306 ); $ a2 = array ('dbuser' => 'root', 'dbpass' => 'pass', 'dbport' => 3305); print_r (array_merge ($ a1, $ a2); print_r ($ a1 + $ a2 );
Method 1: Use the array_merge () function. If the input array contains the same string key name, the value after the key name overwrites the previous one. However, if the array contains a number key name, the subsequent values will not overwrite the original values, but will be appended to the back.
Array ([dbhost] => localhost [dbname] => nextblog [dbport] => 3305 [dbuser] => root [dbpass] => pass)
Method 2: Use the array addition method. If the input array contains the same string key name, the value after this key name will be ignored.
Array ([dbhost] => localhost [dbname] => nextblog [dbport] => 3306 [dbuser] => root [dbpass] => pass)