Forum Moderators: coopster

Message Too Old, No Replies

in_array() ,array_push() issues

in_array() ,array_push() issues

         

kadnan

9:14 pm on Dec 13, 2002 (gmt 0)

10+ Year Member



hello
i ve been trying to make shopping cart with the help of Arrays and Sessions,what I ve been trying to check session var existance if it does then set session var to Array Variable.I am doing something like this
************************************************************
$pid=$_GET['id'];
if( isset($_SESSION['pid'])¦¦ isset($_SESSION['pqty']) ¦¦ isset($_SESSION['pprice'])&&isset($_SESSION['pname']) )
{
echo("all set");
$arrPid=array($_SESSION['pid']);
$arrPQty=array($_SESSION['pqty']);
$arrPName=array($_SESSION['pname']);
$arrPprice=array($_SESSION['pprice']);
}

if(in_array('$pid',$arrPid))
{
$isFound=1;
}
else
{
$isFound=0;
}
echo($isFound);
// if NOt FOUND then push new values
if($isFound==0)
{
$ret_name=array_push($arrPName,$Pname);
}
$_SESSION['pid']=$arrPid;
print_r($_SESSION['pid']);

Ooutput: first it works fine like print_r($_SESSION['pid']) gives
Array ( [0] => A-14 [1] => A-13 ) when i insert 2 different values
3rd time ifi insert say A-15 then it does
Array ( [0] => A-15 [1] => A-15 ) then now whatever i put i overwrites value
Any idea how do make cart with help of array and sessions
Help me please
-adnan

jatar_k

7:27 pm on Dec 14, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I have to admit that I don't quite understand how it is misbehaving.

Do you mean that it works the first time but if you do it again it overwrites everything or is it something else?

This conversation has continued here
[webmasterworld.com...]