mister_t101 Posted March 30, 2006 Share Posted March 30, 2006 Could someone tell me how to print out each element of $_Session['order'] so that the output looks like:posequantitysizefinishposequantitysizefinishIs there something wrong with$formArray=array($pose,$quantity,$size,$finish);array_push($_SESSION['order'],$formArray);foreach ($_SESSION['order'] as $tempArray){print $tempArray[0] . "<br />\n";print $tempArray[1] . "<br />\n";print $tempArray[2] . "<br />\n";print $tempArray[3] . "<br />\n";print "<br />";}[code=php:0]session_start();$_SESSION['order'];$_SESSION['totalPrice'];$_SESSION['basicCost'];$_SESSION['finishUpgrade'];$_SESSION['totalBasicPoints'];$_SESSION['productNumber']; if (array_key_exists('_submit_check', $_POST)) {$pose = $_POST['pose'];$quantity = $_POST['quantity'];$size = $_POST['size'];$finish = $_POST['finish'];$gallery = $_POST['gallery'];$retouch = $_POST['retouch'];$cards = $_POST['cards'];$proofs = $_POST['proofs'];$formArray=array($pose,$quantity,$size,$finish);array_push($_SESSION['order'],$formArray);foreach ($_SESSION['order'] as $tempArray){print $tempArray[0] . "<br />\n";print $tempArray[1] . "<br />\n";print $tempArray[2] . "<br />\n";print $tempArray[3] . "<br />\n";print "<br />";}$_SESSION["productNumber"] += 1;include 'sizeCase.php'; $basicPoints*=$quantity; include 'finishCase.php'; $_SESSION['finishUpgrade']*=10; $_SESSION['upgradedPrice']= $_SESSION['finishUpgrade'] + $basicCost; $_SESSION['totalBasicPoints'] += $basicPoints;$basicPoints = $_SESSION['totalBasicPoints'];$extraPoint = 0;include 'packageCase.php'; $_SESSION['basicCost'] = $basicCost; $_SESSION['extraPoint'] = $extraPoint; $_SESSION['upgradedPrice']= $_SESSION['finishUpgrade'] + $basicCost; print "total Basic Points are ". $_SESSION['totalBasicPoints'] ."<br />\n";print "productNumber is ". $_SESSION["productNumber"] ."<br />\n";print "totalPrice is ". $_SESSION['totalPrice'] ."<br /> \n";print "basic Price is ". $_SESSION['basicCost'] ."<br /> \n";print "Finish Upgrade is ". $_SESSION['finishUpgrade'] ."<br /> \n";print "You get " .$_SESSION['extraPoint']. " extra points. <br />\n";print "The Upgraded Cost is ". $_SESSION['upgradedPrice']. "<br />\n";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6152-printing-out-arrays/ Share on other sites More sharing options...
ober Posted March 30, 2006 Share Posted March 30, 2006 Ok... a few things:1) when using a foreach, it doesn't put the elements into an array.2) You can push an array onto another array with array_push, but it will be stored as an array within an array. Quote Link to comment https://forums.phpfreaks.com/topic/6152-printing-out-arrays/#findComment-22290 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.