Richard_Hollenbeck Posted November 2, 2013 Share Posted November 2, 2013 In my quiz program, I'm getting the following error: PHP Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /~mypath~/quiz.php on line 61 I have two session variables:question_ids is an array, andquestion_pointer is an integer that is supposed to tell the program which question_ids to display. After each question, the question_pointer will get incremented and the next question will be displayed.I get confused with all the single quotes (apostrophes) and double quotes (quotation marks.)Here is the problematic line 61: <?php // ... (other code ) ... print $_SESSION["question_ids[$_SESSION['question_pointer']"]; // line 61 // ... (other code ) ... ?> Since learning about session variables and especially arrays as session variables, I have had a problem visualizing how to write the code to place the session variable as the array element for another session variable. How could I do this that would work? Thanks. Quote Link to comment Share on other sites More sharing options...
PravinS Posted November 2, 2013 Share Posted November 2, 2013 try this <?php print $_SESSION[$question_ids[$_SESSION['question_pointer']]; ?> Quote Link to comment Share on other sites More sharing options...
Solution ignace Posted November 2, 2013 Solution Share Posted November 2, 2013 (edited) $id = $_SESSION['question_ids'][ $_SESSION['question_pointer'] ]; Edited November 2, 2013 by ignace Quote Link to comment Share on other sites More sharing options...
Richard_Hollenbeck Posted November 2, 2013 Author Share Posted November 2, 2013 print $_SESSION['question_ids'][$_SESSION['question_pointer']]; // line 61 did the trick. Thanks to PravinS and ignace Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.