Re: How to use a variable variable with an array [solved]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear Robert,

On 14.12.2011, at 22:02, Robert Cummings wrote:

> $path = ‘/path/to/data/in/my/arbitrarily/deep/array/';
> $array = $someBigFatArray;
> $focus = &$array;
> foreach( explode( '/', $path ) as $step )
> {
>     if ($step === '' || $step === 'CONFIGURATION’)
>     {
>         continue;
>     }
>     if( isset( $focus[$step] ) )
>     {
>         $focus = &$focus[$step];
>     }
>     else
>     {
>         unset( $focus );
>         $focus = null;
>         break;
>     }
> }
> echo "<pre>"; echo var_export($focus, TRUE); echo "</pre>";

This solution is excellent! I modified it a little to match for empty $step and then continue, just in case there is a leading, ending or doubled “/“ and same for CONFIGURATION which will be my indicator to find the values where we expect a value replacement.

       if ($step === '' || $step === 'CONFIGURATION’) {
           continue;
       }


Great thing!

Thanks a lot to all!

Cheers, Nils
-- 
http://webint.cryptonode.de / a Fractal project


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux