|
-
Sep 5th, 2001, 01:01 AM
#1
Thread Starter
Junior Member
Simple PHP Array Question
Here is my code:
<code>
if (!isset($cookie_cart)){
$cookie_cart = array();
}
$string = $quantity . "x " . $size . " " . $item;
$cookie_cart[] = $string;
setcookie("cookie_cart", $cookie_cart, time()+1800);
</code>
I want it to check to see if the variable $cookie_cart is set. If it is, then it is set as an array and I can continute. If it isn't, then it sets it as an array. I get an error because it claims that $cookie_cart is not an array and that I cant use '[]' with strings. Any ideas why this is happening?
Thanks.
-
Sep 5th, 2001, 03:50 PM
#2
did you try to add a number in the [ ]
PHP Code:
if (!isset($cookie_cart)){
$cookie_cart = array();
}
$string = $quantity . "x " . $size . " " . $item;
$cookie_cart[1] = $string;
setcookie("cookie_cart", $cookie_cart, time()+1800);
-
Sep 5th, 2001, 03:54 PM
#3
or you can try it like this
PHP Code:
if (!isset($cookie_cart)){
$string = $quantity . "x " . $size . " " . $item;
$cookie_cart = array('$string');
}
setcookie("cookie_cart", $cookie_cart[0], time()+1800);
don't know if you need the ' ' in the array.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|