Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6645993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:21:31+00:00 2026-05-26T00:21:31+00:00

I have stored array values in PHP session. Now I want to retreive this

  • 0

I have stored array values in PHP session.

Now I want to retreive this array and convert it to javascript aray.

This is how I set PHP session:

var listone = ["one", "two", "three"];

function setSession(listone){
    $.get(
        "setSession.php",
        {listone:listone} 
    );
}

So if once these values are set and I refresh the page, I check if the session has been set. If set, I want to do something like this:

<?php
session_start();
if(isset($_SESSION['listone']))
{
?>
  listone = Array('<?php echo json_encode($_SESSION['listone']) ?>');
<?php
}
?>

When I do this, the ‘listone’ array is showing me like this:

listone[0] = [
listone[1] = "
listone[2] = o
listone[3] = n
listone[4] = e
listone[5] = "
.... etc

I know I am doing something wrong.
Is it the way I am storing the array in PHP session?
or
Is it the way I am retrieving it back to JS?

Thanks for any pointers. I am willing to dig more if guided properly 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:21:32+00:00Added an answer on May 26, 2026 at 12:21 am

    You may be trying to do one of two things here- either something to do with AJAX, which is expecting a JS response, or you’re trying to access a session variable directly in JS.

    If you simply wish to switch a PHP variable into a JS readable array, you can do:

    json_encode($_SESSION['myarray']);
    

    This would need to be a response readable & interpreted elsewhere by a JS script (e.g. an AJAX response).

    PHP session variables arent accessable through JS directly, however, you can construct JS within PHP, wrapping the two together so you use PHP to output JS populated with the data held within your PHP session variable. The key here is the order of the code, and how your JS is structured- i.e. you will probably want to reference a global JS variable so the values are accessible by your other JS- or call a function etc…

    So, you could have:

    session_start();
    if(!isset($_SESSION['myarray'])){
             $_SESSION['myarray']=array('one', 'two', 'three');
    }
    
    echo "<script type='text/javascript'>
    
    var myJSvariable = new Array();";
    
    foreach($_SESSION['myarray'] as $key=>$value){
          echo "myJSvariable[".$key."]=".$value.";";
    }
    
    echo "</script>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have classname stored in variable $classname; also I have an array of values
I have CSV text thats stored in the session array as csv. The lines
I have multiple $_POST values which I want to store in an array to
I have a problem with getting some html value stored in a php array:
I have myself a linear grid of Vector2s stored in a Vector2[,] array, and
Overview: I have an array of 20 byte strings that needs to be stored
A cancer CT picture is stored inside a unsigned short array (1-dimensional). I have
I have this code in jquery: $.ajax({ type: POST, url: tosql.php, data: {textnode: textnode},
I have a custom PHP function which executes a stored procedure and returns an
While working with ActiveRecord I have a table which stores a serialized array of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.