← All built-ins / array_replace()

array_replace()

array_replace(...$args): mixed

Parameters

NameTypeDescription
$...arraybase array, then replacement arrays

Return value

The base array with later arrays overwriting by key (keys preserved).

Example

$r = array_replace(["a" => 1, "b" => 2], ["b" => 9, "c" => 3]);
echo $r["a"], $r["b"], $r["c"];
193

See also

array_merge()array_diff()