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 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. 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 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. 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. 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. 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. 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 ? 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 ? 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.. Link to comment https://forums.phpfreaks.com/topic/186558-in_array-help/#findComment-985316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.