dink87522 Posted December 29, 2009 Share Posted December 29, 2009 My code on one page is: $_SESSION['q20'] = $countries[$rndWork]."D".$answer."D".$answer_result; and on the next page is: $q20 = $_SESSION['q20']; for ($i = 0; $i < 3; $i = $i + 1){ $q20Split = array_slice(explode("D", $q20), i, 1); $question20[i] = $q20Split; } ?> however I get the following error which I have never seen before: Warning: array_slice() expects parameter 2 to be long, string given in /home/public_html/geographytrainer.com/hsDis.php on line 31 Warning: array_slice() expects parameter 2 to be long, string given in /home/public_html/geographytrainer.com/hsDis.php on line 31 Warning: array_slice() expects parameter 2 to be long, string given in /home/public_html/geographytrainer.com/hsDis.php on line 31 Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/ Share on other sites More sharing options...
premiso Posted December 29, 2009 Share Posted December 29, 2009 $q20Split = array_slice(explode("D", $q20), $i, 1); You forgot the $ before i. Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985236 Share on other sites More sharing options...
dink87522 Posted December 29, 2009 Author Share Posted December 29, 2009 Doh! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985237 Share on other sites More sharing options...
dink87522 Posted December 29, 2009 Author Share Posted December 29, 2009 $q20 = $_SESSION['q20']; echo("q2a: $q20"); for ($i = 0; $i < 3; $i = $i + 1){ $q20Split = array_slice(explode("D", $q20), $i, 1); $question20[i] = $q20Split; } echo("q0: ".$question20[0]); echo("q1: ".$question20[1]); echo("q2: ".$question20[2]); q2a prints "GrenadaDSt. George'sD0" q0, 1, 2 do nit print. Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985240 Share on other sites More sharing options...
dink87522 Posted December 29, 2009 Author Share Posted December 29, 2009 I want it so that q0 prints "Grenada", q1 prints "St. George" and q2 prints "0". Currently they are all printing empty. Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985245 Share on other sites More sharing options...
premiso Posted December 29, 2009 Share Posted December 29, 2009 $question20[$i] = $q20Split; Once again you forgot the $ before the i. Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985252 Share on other sites More sharing options...
dink87522 Posted December 29, 2009 Author Share Posted December 29, 2009 Hmm, still doesn't work. q2a prints "GrenadaDSt. George'sD0" while q0 prints "Array", q1 prints "Array" and q2 prints "Array" Sorry I am only a beginner at PHP. Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985256 Share on other sites More sharing options...
dink87522 Posted December 29, 2009 Author Share Posted December 29, 2009 ? Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985267 Share on other sites More sharing options...
dink87522 Posted December 29, 2009 Author Share Posted December 29, 2009 ? Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985304 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 $q20 = $_SESSION['q20']; $q20Split = explode("D", $q20); Should do exactly what you want.. Quote Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985316 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.