I would like to know the difference between array_replace
and array_merge
, because in some cases the two seem to have similar behaviors.
Example:
$informacoes = ['nome' => 'wallace', 'idade' => 36];
array_replace($informacoes, ['idade' => 26]);
Output:
[
"nome" => "wallace",
"idade" => 26,
]
In the case of array_merge
, we have the same result:
array_merge($informacoes, ['idade' => 26]);
Output:
[
"nome" => "wallace",
"idade" => 26,
]
-
What is the main difference between the two?
-
When should I use one or the other?