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. Link to comment https://forums.phpfreaks.com/topic/283526-session-variable-as-array-element-for-another-session-variable/ 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']]; ?> Link to comment https://forums.phpfreaks.com/topic/283526-session-variable-as-array-element-for-another-session-variable/#findComment-1456571 Share on other sites More sharing options...
ignace Posted November 2, 2013 Share Posted November 2, 2013 $id = $_SESSION['question_ids'][ $_SESSION['question_pointer'] ]; Link to comment https://forums.phpfreaks.com/topic/283526-session-variable-as-array-element-for-another-session-variable/#findComment-1456576 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 Link to comment https://forums.phpfreaks.com/topic/283526-session-variable-as-array-element-for-another-session-variable/#findComment-1456602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.