Explain It plzzzzzz.....

function remove_product($pid){
	$pid=intval($pid);
	$max=count($_SESSION['cart']);
	for($i=0;$i<$max;$i++){
		if($pid==$_SESSION['cart'][$i]['productid']){
			unset($_SESSION['cart'][$i]);
			break;
		}
	}
	$_SESSION['cart']=array_values($_SESSION['cart']);

Can Any one explain those lines…i mean why $i & productid enter in session array???

if($pid==$_SESSION[‘cart’][$i][‘productid’]){
unset($_SESSION[‘cart’][$i]);
break;
}
}
$_SESSION[‘cart’]=array_values($_SESSION[‘cart’]);

From the looks of it you have an array in session called Cart…

The cart array consist of 0 to many different carts. Each of those causes can contain 0 to many products.

So the $i seems to be used to identify which cart is in use, So the $i is used to define which cart.

The person who wrote it used session as temporary place to store what the person wanted while they were browsing the site.

That’s my interpretation.

thanks bro… ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service