Example 1 — Override Nested Settings
Change only the database port and the debug flag.
<?php
$defaults = ["db" => ["host" => "localhost", "port" => 3306], "debug" => false];
$custom = ["db" => ["port" => 3307], "debug" => true];
$config = array_replace_recursive($defaults, $custom);
echo json_encode($config), PHP_EOL; How It Works
- Create the defaults. The
dbsetting has a host and a port. - Create the custom settings. They only change
portanddebug. - Call array_replace_recursive(). The nested
dbarrays are merged by key. - Read the result. The host is kept and the port is changed.

