Re: Re: How to read PHP variables.
| From: | André Medeiros | Date: | Fri, 15 Jul 2005 18:46:39 +0000 |
| Subject: | Re: Re: How to read PHP variables. | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-218767@lists.php.net to get a copy of this message | ||
What about...
<form action="saveConfig.php" method="post">
Database Host: <input type="text" name="config[database][host]"
value="<?=$config['database']['host']?>" /><br />
Database User: <input type="text" name="config[database][user]"
value="<?=$config['database']['user']?>" /><br />
<!-- some more fields here -->
</form>
And then...
<?php
$newConfigValues = $_POST['config'];
$fileCode = "<?php\n// AUTOMATICLLY CREATED CONFIG FILE. DO NOT EDIT!
\n";
foreach( $newConfigValues as $parentConfigKey => $parentConfigValue ) {
if( is_array( $parentConfigValue ) {
foreach( $parentConfigValue as $childConfigKey => $childConfigValue )
{
$fileCode .= "$config['$parentConfigKey']['$childConfigKey'] =
'$childConfigValue';\n";
}
}
else {
$fileCode .= "$config['$parentConfigKey'] = '$parentConfigValue'\n";
}
}
$fileCode .= "?>";