[nycphp-talk] accessing $_SESSION elements
Brian Pang
bpang at bpang.com
Fri Oct 24 12:33:00 EDT 2003
for ($i = 1; $i <= 10; $i++) {
if (isset($_SESSION[$i.'_fair_name'])) {
echo ("success");
}
}
I think that'll work
or this
$_SESSION[${$i.'_fair_name'}]
check the manual under "variable variables"
> Hi all,
>
> I'm trying to avoid a bunch of if/then statements by looping through
> $_SESSION. I hit a roadblock that I can't seem to get around. Here is
> a simple piece of code which I think gets to the heart of the problem:
>
> $begin=1;
> if(isset($_SESSION['$begin_fair_name']))
> {
> echo "success";
> }
>
> Of course, this works:
> if(isset($_SESSION['$1_fair_name']))
> {
> echo "success";
> }
>
> BUT, I have between 1 and 10 fair_name fields (i.e. 1_fair_name,
> 2_fair_name) coming from the form. It would be much more efficient if
> I can loop through and perform operations as opposed to a bunch of
> if/then statements referring to specific fair_name fields. Obviously
> the problem is with using a variable inside the array and I haven't
> been able to figure out how to work around it.
>
> Trying to keep it brief here, but please let me know if further details
> would be helpful. I would appreciate any tips or suggestions.
>
> Thanks!
>
> -Aaron
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>
>
More information about the talk
mailing list