Results 1 to 3 of 3

Thread: Simple PHP Array Question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    28

    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.

  2. #2
    scoutt
    Guest
    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_carttime()+1800); 

  3. #3
    scoutt
    Guest
    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
  •  



Click Here to Expand Forum to Full Width