Re: looping variables from a file
| From: | John W. Holmes | Date: | Wed, 24 Mar 2004 18:23:02 +0000 |
| Subject: | Re: looping variables from a file | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-181386@lists.php.net to get a copy of this message | ||
Second what Rich said, keep replies to the list, please. This can benifit
everyone.
---John Holmes...
----- Original Message -----
From: "John W. Holmes" <holmes072000@charter.net>
To: "Ryan A" <ryan@coinpass.com>
Cc: <rich@launchcode.co.uk>
Sent: Wednesday, March 24, 2004 1:22 PM
Subject: Re: [PHP] looping variables from a file
> From: "Ryan A" <ryan@coinpass.com>
>
> > I knew this would be complicated when I started to write to the list for
> > help but didnt know so
> > complicated....I can just about understand (barely) what you guys are
> > telling me but dont know
> > where to start..can you give me some starting code example/s which I can
> > build on?
>
> Sure...
>
> $array1 = get_defined_vars();
> include('yourfile.php');
> $array2 = get_defined_vars();
>
> $newvars = array_diff($array2,$array1);
> foreach($newvars as $name => $value)
> { echo "$name = <font color=\"green\">$value</font><br
> />\n"; }
>
> Actually, if you said there were arrays inside the include file, it may
get
> a little more complicated. If they are one dimensional arrays, you can
test
> $value with is_array() and maybe implode() the values into a string to
> display.
>
> if(is_array($value))
> { echo implode(',',$value); }
> else
> { echo $value; }
>
> If there are multi-dimensional arrays, then you'll need a recursive
> function. Have fun!
>
> ---John Holmes...
>
> PS: This is all assuming the user comments are correct and variables from
> include()'d files are captured by get_defined_vars().
>