Jump to content

Archived

This topic is now archived and is closed to further replies.

mister_t101

printing out arrays

Recommended Posts

Could someone tell me how to print out each element of $_Session['order'] so that the output looks like:

pose
quantity
size
finish

pose
quantity
size
finish

Is 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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.