PHP Programming > Beginners - Learning PHP
Problem defining variable
lostnvegas:
I'm not sure I understand where to put the selected option (sorry, it's my learning disability). I haven't tried printing the array. I've never done it but I think I know how. I added several things to it with no problem (IE the shipping cost, though that info comes from the server, not a variable). I will try printing the array and see how it goes. Any other suggestions?
Noodles:
Because I do not know if the size variable is assigned to size its hard to start but if you dump the arrays to see how they look it will tell you more.
Where it vanishes try these to start with they might tell you a lot of information on your arrays and session data.
--- PHP Code: ---
print_r()
or
var_dump()
print_r ($_SESSION);
--- End code ---
lostnvegas:
ok using print_r ($_SESSION); I got the following array info:
--- PHP Code: ---Array ( [username] => lostnvegas [cart_array] => Array ( [1] => Array ( [item_id] => 11 [quantity] => 1 [size] => xxxl ) ) )
--- End code ---
Noodles:
With the other fuctions print_r, var_dump you need to add the array var to it to get it to print it out to the screen.
--- PHP Code: ---var_dump($var_array_name);
--- End code ---
Can you try and use:
--- PHP Code: ---
$size = $_session['cart_array']['1']['size'];
echo $size;
--- End code ---
lostnvegas:
no matter where i put
--- PHP Code: ---$size = $_session['cart_array'][1]['size'];
--- End code ---
I still get an undefined variable error
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version