declaring array as a session variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kumuda v
    New Member
    • Jul 2007
    • 21

    declaring array as a session variable

    Hello all,

    I want to pass the array from one php page to other php page. So how to make array as an session variable.

    with regards
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Originally posted by kumuda v
    Hello all,

    I want to pass the array from one php page to other php page. So how to make array as an session variable.

    with regards
    Hi kumuda v

    I think you can simply do the following

    Starting Page
    [php]
    <?php
    session_start() ;

    // assuming array is defined as $laArray for simplicity

    $_SESSION['my_array'] = $laArray ;

    ?>
    [/php]
    Target page:
    [php]
    <?php
    session_start ;

    $laArray = $_SESSION['my_array'] ;

    // you can now use $laArray in whatever wway you wnat

    // write it back to the $_SESSION
    $_SESSION['my_array'] = $laArray ;
    ?>
    [/php]


    This should do the trick for you. I'm not sure if it is possible to manipulate the array within the $_SESSION array - it should be, but I would find that confusing so I would always extract it first for clarity in code.

    I have not tried this idea but I think it should work. Have a go and ost back with any problems - be sure to load code into code tags.

    Cheers
    nathj

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya Kumuda.

      Have a look at these articles:
      The Array Type
      External Variables

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Merged duplicate posts.

        Comment

        • kumuda v
          New Member
          • Jul 2007
          • 21

          #5
          Thank you,
          I got the solution for that.

          With regards

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Kumuda.

            Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

            Comment

            Working...