OK, after hearing all the feedback from everybody here, I've decided to make a "compromise." My main beef with the existing array syntax is its bad readability, which can certainly be improved (a lot) by using indentation.
Because I am lazy to indent (and the files I am writing are huge), I opted for JSON (or any syntax that's more readable than PHP's). I didn't make myself very clear, but another strong reason why I am using the JSON format because many other people will be looking at these config files. Most of them are not PHP-savvy and JSON is a much more human-readable format.
Unfortunately PHP code formatters/beautifiers out there don't do anything to array formatting, so I coded my own. It is based on that ugly piece of code I wrote above (and it is uglier), but it does the job.
The result is now I basically have an array beautifier, and I can generate readable native PHP code while being lazy. That's all I wanted, thanks everybody for the suggestions and pointers.
PS: Here's the beautified Kohana config array I generated with my function:
array (
'default' => array (
'type' => 'mysql',
'connection' => array (
'hostname' => 'localhost',
'database' => 'kohana',
'username' => false,
'password' => false,
'persistent' => false
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => false,
'profiling' => true
),
'alternate' => array (
'type' => 'pdo',
'connection' => array (
'dsn' => 'mysql:host=localhost;dbname=kohana',
'username' => 'root',
'password' => 'r00tdb',
'persistent' => false
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => false,
'profiling' => true
)
);
Which doesn't look bad at all.