Multidimensional Array...

From: Date: Thu, 18 Oct 2001 19:45:22 +0000
Subject: Multidimensional Array...
Groups: php.general 
Request: Send a blank email to php-general+get-71518@lists.php.net to get a copy of this message
Hello there... The problem is that I can only add one value into the array... Anyone knows what I'm doing wrong here....(First project by the way!!) ===================================================== <?php session_start(); session_register("offer"); // Make a new offer if it doesn't exist yet if (!is_array($offer)) { $offer = array(array('pid' => '', 'pname' => '', 'pqty' => '')); $nrItems = 0; } // Get variables from products.php $productID=trim(${"pid"}); $productName=trim(${"productName"}); // Add product to offer if ($productID!="") { $nrItems = $nrItems + 1; for ($i=0; $i<$nrItems; $i=$i+1) { if ($offer[$i]['pid']=="") { $productQTY = 1; $offer[$i]['pid'] = $productID; $offer[$i]['pname'] = $productName; $offer[$i]['pqty'] = $productQTY; } } } //if there are no items in the offer, print a message if ($offer[0]['pid']=="") { echo "No items in the offer"."<br>\n"; var_dump($offer)."<br>\n"; echo "<a href=producten.php>back</a>"; } //else print the contents of the offer else { for ($i=0; $i<$nrItems; $i=$i+1) { echo "The offer:"."<br>\n"; var_dump($offer)."<br>\n"; echo "The offer contains items: "; echo $nrItems."<br>\n"; echo $offer[$i]['pid']."<br>\n"; echo $offer[$i]['pname']."<br>\n"; echo $offer[$i]['pqty']."<br>\n"; echo "<br>\n"; echo "<a href=producten.php>back</a>"; echo "<br>\n"; } } ====================================================== THNX in advance

« previous php.general (#71518) next »