PHP session array

前端 未结 4 1249
悲哀的现实
悲哀的现实 2020-12-22 03:20

how can i store this array into a session and use sessions to move the elements inside the array up/down/left/right diagonally

$board = array(A B C D E F G H         


        
相关标签:
4条回答
  • 2020-12-22 04:01

    You store it in a session like

    <?php
    session_start();
    $board=array('whatever');
    $session['board']=$board;
    

    As for manipulation, it is just a normal array. You can work with it like any other array.

    0 讨论(0)
  • 2020-12-22 04:12

    Call session_start and afterwards store your variables in $_SESSION -- they will be available throughout the session:

    session_start();
    $_SESSION['board'] = array( ... );
    

    Moving elements is just a matter of assigning one value to another, for example:

    $_SESSION['board'][$new_i][$new_j] = $_SESSION['board'][$old_i][$old_j];
    $_SESSION['board'][$old_i][$old_j] = ...;
    
    0 讨论(0)
  • 2020-12-22 04:15

    $_SESSION['myArray'] = $board;

    and you can access any element using $_SESSION['myArray'][i][j];

    0 讨论(0)
  • 2020-12-22 04:16

    Yes. you can store and update an array in session. use like this :

    session_start();
    $_SESSION['youarray'] =$board;
    

    and now do updates in $_SESSION['youarray'] array according to your requirement that will be like normal array. but stored in session.

    0 讨论(0)
提交回复
热议问题