$basket[$fruit] = $num; } function delete_item( $fruit, $num ){ if( $basket[$..."/>

php script logic problem?

<html>
<head>
<title>Test</title>
</head>

<body>


<?php

class Cart
{
var $basket;

function add_item( $fruit, $num ){
$this->$basket[$fruit] = $num;
}

function delete_item( $fruit, $num ){

if( $basket[$fruit] > 0 ){
$this->basket[$fruit] -= $num;
return true;
}else{
return false;
}
}

function print_this(){

if( $basket[$fruit] > 0 ){
for($i=0;$i<num;$i++){
print "basket[i]";
}
}
else{
print "Basket is empty";
}
return true;
}


}


$shop = new Cart;

$shop->add_item("Apple",1);
$shop->add_item("Orange",2);
$shop->add_item("Cherry",3);

$shop->print_this();

?>

</body>
</html>

Hi,

Anyone know why the output is "Basket is empty"?

It should print Apple, Orange, and Cherry.

 

 

 

 

Top