Accessing sessions in loop:

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Antoni

    #1

    Accessing sessions in loop:

    Hello,

    Could anyone advise, if I had three sessions as below, is there anyway
    I could access the three in a loop.

    $_SESSION['item1'];
    $_SESSION['item2'];
    $_SESSION['item3'];

    Thank you
  • Justin Wyer

    #2
    Re: Accessing sessions in loop:

    Antoni wrote:
    [color=blue]
    > Hello,
    >
    > Could anyone advise, if I had three sessions as below, is there anyway
    > I could access the three in a loop.
    >
    > $_SESSION['item1'];
    > $_SESSION['item2'];
    > $_SESSION['item3'];
    >
    > Thank you[/color]
    You cannot have 3 sessions, you can only have one session. You have 3
    session variables there and yes you can access them in a loop.

    And your question makes no sense?

    Comment

    • Pieter Nobes

      #3
      Re: Accessing sessions in loop:

      Antoni wrote:[color=blue]
      > Hello,
      >
      > Could anyone advise, if I had three sessions as below, is there anyway
      > I could access the three in a loop.
      >
      > $_SESSION['item1'];
      > $_SESSION['item2'];
      > $_SESSION['item3'];
      >
      > Thank you[/color]
      <?php
      for ( $i = 0; $i++; $i <= 3 ) {
      echo $_SESSION['item' . $i];
      }
      ?>

      --
      Pieter Nobels

      Comment

      • Elliott C. Bäck

        #4
        Re: Accessing sessions in loop:

        Antoni wrote:
        [color=blue]
        > Hello,
        >
        > Could anyone advise, if I had three sessions as below, is there anyway
        > I could access the three in a loop.
        >
        > $_SESSION['item1'];
        > $_SESSION['item2'];
        > $_SESSION['item3'];
        >
        > Thank you[/color]

        foreach($_SESSI ON as $key => $value){
        // do things
        }

        or

        for($i = 1; $i <= 3; $i++){
        $var = $_SESSION["item$i"];
        }

        --
        Elliott C. Bäck
        Burada en kaliteli ve en iyi canlı bahis sitelerini bulabilirsiniz. Türk kullanıcılara 2026 yılı itibariyle sunulan en güvenilir opsiyonlar sitemizde.

        Comment

        • kingofkolt

          #5
          Re: Accessing sessions in loop:

          "Pieter Nobes" <pieterRE@MOVE. opengate.be> wrote in message
          news:7q2Vc.2190 25$fx5.10753094 @phobos.telenet-ops.be...[color=blue]
          > Antoni wrote:[color=green]
          > > Hello,
          > >
          > > Could anyone advise, if I had three sessions as below, is there anyway
          > > I could access the three in a loop.
          > >
          > > $_SESSION['item1'];
          > > $_SESSION['item2'];
          > > $_SESSION['item3'];
          > >
          > > Thank you[/color]
          > <?php
          > for ( $i = 0; $i++; $i <= 3 ) {[/color]
          [...]

          The $i must = 1 not 0.


          Comment

          Working...