CassidyHunt
IS-IT--Management
I am testing out a theory and want to know why I get it to echo the $i variable but not the $obj variable in my foreach loop. It loops through with the 6 positions of the array just does not print the value.
Am I doing something wrong?
Thanks
Cassidy
Am I doing something wrong?
Code:
<?php
class shoppingcart
{
var $item_index;
var $cart_item;
function additem($qty,$productcode,$description,$weight,$price)
{
if(!isset($this->item_index)) { $this->item_index = 0; }
else{ $this->item_index++; }
$cart_item[$this->item_index] = new item;
$cart_item[$this->item_index]->qty = $qty;
$cart_item[$this->item_index]->productcode = $productcode;
$cart_item[$this->item_index]->description = $description;
$cart_item[$this->item_index]->weight = $weight;
$cart_item[$this->item_index]->price = $price;
$cart_item[$this->item_index]->status = "Active";
echo $cart_item[$this->item_index]->productcode . "<BR>";
return false;
}
function removeitem($index)
{
$this->cart_item[$index]->status = "Deleted";
return false;
}
function getitem($index)
{
$item = array($this->cart_item[$index]->qty,
$this->cart_item[$index]->productcode,
$this->cart_item[$index]->description,
$this->cart_item[$index]->weight,
$this->cart_item[$index]->price,
$this->cart_item[$index]->status);
return $item;
}
}
class item
{
var $qty;
var $productcode;
var $description;
var $weight;
var $price;
var $status;
}
?>
<?php
$myobj = new shoppingcart;
$myobj->additem('3','A100','Magical Widget #1','3lbs','6.00');
$myobj->additem('2','A101','Magical Widget #2','2lbs','4.00');
$myobj->additem('1','A102','Magical Widget #3','1lbs','2.00');
for($i = 0; $i < 3; $i++ ) {
$myitem = $myobj->getitem($i);
foreach($myitem as $obj){ echo $i . ". " . $obj . "<br>"; }
}
echo "complete";
?>
Thanks
Cassidy