On Tue, Nov 9, 2010 at 6:55 PM, Daevid Vincent <[email protected]> wrote:
> I've used variable variables before but for some reason I can't figure this
> snippet out. Why doesn't $ini_file get set (or appended to).
>
AFAIK variable variables can only reference actual variables--not array
subscripts or other non-variable syntax elements such as "->" or "::".
eval() can do this because it parses the code as PHP. Variable variables
take the *variable name* contained in the variable and look it up in the
current scope. This is a variable name:
ini_array
This is not:
ini_array['agis_core']['adapter']
I think you can use references here to do what you need. Warning: I only
tested the basics of this in the interpreter without running this exact
code.
public function explode_ini()
{
$ini_array = array();
foreach($this->ini_array as $heading => $key_vals)
{
foreach ($key_vals as $k => $v)
{
$path = &$ini_array[$heading];
$subsection = explode('.', $k);
foreach ($subsection as $ss)
$path = &$path[$ss];
$path = $v;
unset($path);
}
}
$this->ini_array = $ini_array;
}
David