Arrays
Posted: Mon Oct 18, 2004 7:45 am
Code: Select all
<?php
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('html_errors', false);
//set new product flag to zero
$new = 0;
//Conver URL variable to normal variables
$Product = $_GET['Product'];
$Qty = $_GET['Qty'];
$Price = $_GET['Price'];
//Is there a cart and if not create one
if(!isset($_SESSION['cart']))
{
$_SESSION ['cart'][] = array();
$_SESSION ['items'] = 0;
$_SESSION ['Total Price']= 0.00;
}
//Has the Array been initialised if it has...
if(isset($_SESSION ['cart'])){
foreach($_SESSION ['cart'] as $key){
foreach( $key as $element){
echo $element . '<br>';
if($element[0] == $Product){
// If the product exists then we need to update the quantity
$_SESSION ['cart'][$key][1] = + $Qty;
}
else{
// if the product isn't in the basket
$new = 1;
}
}
}
}
if($new == 1){
//if the add new variable is 1 then append another array to cart
$_SESSION ['cart'][] = array($Product,$Qty,$Price);
}
//Debug
echo '<pre>';
print_r($_SESSION ['cart']);
echo '</pre>';
?>
?>Code: Select all
echo $element . '<br>';
if($elementї0] == $Product){How do i access the value of $element[0]
?>