Adding values to an array
Posted on 2003-11-08
I'm making a little shopping cart using arrays and sessions...
I was wondering, how would I add an item to an existing array of things when the user clicks "Add to cart". Meaning, I have the page setup down ok, but like if I have:
$existing_array = array("SomeItem","SomeItem2");
How would I tell PHP to add "SomeItem3" into the $existing_array? I guess what I'm asking is...how do I add elements to an array as I go along? And also, sessions can store arrays correct? So I could do the following:
$_SESSION[arrayname] = $initialized_array
$existing_array = array();
Is that ok? Or do I need to change my logic?
Thank you much in advance.