Use var_export

PHP Code: 
<?php

//Load your file and change values like so:
include 'yourphpfile.php';
$options['user_dir'] = 'New String';

//var_export prints the result in a way it can be read again by PHP
$contents "<?php\r\n" ' $options = ' var_export($options,true) . "\r\n" ' ?>';

//Put the new contents in the file.
file_put_contents('yourphpfile.php',$contents);
?>
Your new contents would look like so:

PHP Code: 
<?php
$options 
= array(
    
'used_dir' => 'New String'
    
'login' => true
)
?>
No too hard!

http://php.net/manual/en/function.var-export.php