PHP array in $_SESSION - weird result

can anyone explain this to me?:

if (isset($_SESSION['pack'])){
   if (is_array($_SESSION['pack'])){
      foreach ($_SESSION['pack'] as $pack){
         //code
      }
   }
}

i get:

Warning: Invalid argument supplied for foreach()

and if i do

die(var_dump($_SESSION['pack']));

i get

array(1) { [0]=> string(2) "16" } 

i'm really going bonkers with this one, i need it ready for tonight and i'm stuck with this...

Thanks

Upvotes: -1

Views: 120

Answers (1)

fab
fab

Reputation: 1859

Regarding the line

foreach ($_SESSION['pack'] as $pack){...

If you have register_globals enabled, $_SESSION['pack'] will be the same as $pack. That might produce the weird results. Either make sure register_globals is disabled, or rename $pack to something else.

Upvotes: 3

Related Questions