tauchai83 Posted January 14, 2007 Share Posted January 14, 2007 how to pass the array to next page?I have been in trouble in passing array to next page.The array i use include foreach statement as following.if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; }I would like to have the items selected by user pass along to next page Link to comment https://forums.phpfreaks.com/topic/34085-help/ Share on other sites More sharing options...
fert Posted January 14, 2007 Share Posted January 14, 2007 $_GET or put them in hidden form fields Link to comment https://forums.phpfreaks.com/topic/34085-help/#findComment-160236 Share on other sites More sharing options...
papaface Posted January 14, 2007 Share Posted January 14, 2007 or store it in a session. Link to comment https://forums.phpfreaks.com/topic/34085-help/#findComment-160237 Share on other sites More sharing options...
scotmcc Posted January 14, 2007 Share Posted January 14, 2007 You could pass it in the session (as above), or if you really want to you can pass it from the page as a form value. This is probably not the best way to handle passing an array, but it works.Try this example:[code]<?php// Create your array$myarray = array('test','test2','test3');// encode the array and place it into your form$myarray = base64_encode(serialize($myarray));// post the form and get the array back from the page$newarray = unserialize(base64_decode($myarray));// echo the outputfor($i=0;$i<3;$i++) {echo $newarray[$i].'<br>';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/34085-help/#findComment-160239 Share on other sites More sharing options...
tauchai83 Posted January 14, 2007 Author Share Posted January 14, 2007 so in my case how the coding should look like? can anyone modify for me? i donno the way to pass array...normal value i know using <input type="hidden" value="$xxx">.. how about for array that the element is unknown? as the case above..php newbies here..hehe Link to comment https://forums.phpfreaks.com/topic/34085-help/#findComment-160240 Share on other sites More sharing options...
scotmcc Posted January 14, 2007 Share Posted January 14, 2007 Create these 2 pages:page1.php[code]<?php// Create your array$myarray = array('test','test2','test3');// Put this into your form$myarray = base64_encode(serialize($myarray));?><form method="post" action="page2.php"> <input type="text" name="myarray" value="<?php echo $myarray; ?>"> <input type="submit" /></form>[/code]page2.php[code]<?php// get the array back from the form$newarray = unserialize(base64_decode($_REQUEST['myarray']));// echo the outputfor($i=0;$i<3;$i++) {echo $newarray[$i].'<br>';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/34085-help/#findComment-160258 Share on other sites More sharing options...
tauchai83 Posted January 14, 2007 Author Share Posted January 14, 2007 from my code...i fail to utilize your code....coz is little bit different thing... Link to comment https://forums.phpfreaks.com/topic/34085-help/#findComment-160399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.