Hi, I took this piece of code from
http://www.php.net/manual/en/reserved.variables.php#reserved.variables.cookies
and changed it a little. I want to take the values from the cookie and store them in an array.
This is the code: ($ar is $HTTP_COOKIE_VARS)
function display($ar){
while(list($key,$val)=each($ar)){
$arr[$key] = $val;
echo "$key = $arr[$key]<BR>";
if (is_array($val)){
display($val);
}
}
$v[$r]=$arr["Name"];
$r++;
$v[$r]=$arr["BuyAddress1"];
$r++;
$v[$r]=$arr["BuyAddress2"];
$r++;
$v[$r]=$arr["BuyCity"];
$r++;
$v[$r]=$arr["BuyState"];
$r++;
$v[$r]=$arr["BuyZip"];
$r++;
$v[$r]=$arr["BuyEmail"];
$r++;
$v[$r]=$arr["DayPhone"];
$r++;
$v[$r]=$arr["EvePhone"];
$r++;
}
Now, the array ($v) would be empty. So, I tested the process.
There are two loops. The first time everyting works fine. These are the results I get:
cookie = Array
Name = Panos A. (NY)
BuyAddress1 = 9919 Ave Z
BuyAddress2 = ap 2B
BuyCity = Brooklyn
BuyState = NY
BuyZip = 11235
BuyEmail = appanos@hotmail.com
DayPhone = (718) 555 - 3688
EvePhone = 718 555-5107
The second times it erases all the array values so they come out empty:
cookie =
Name =
BuyAddress1 =
BuyAddress2 =
BuyCity =
BuyState =
BuyZip =
BuyEmail =
DayPhone =
EvePhone =
I tried setting a count ($c=1; code here and then $c++) so that if ($c != 1) it won't perform the loop. Doesn't work and it doesn't make sence to me why it does this.
Help please, goin' slightly crazy here.
Thank u,
Panos A.