I am trying to add to an array with a form, and am stuck. I can hard code the things into my array, but I am not quite sure how to add something to the bottom of my array. Here is the array itself: $_SESSION['items'] = array( array($_POST['item_desc'],$_POST['quantity'],$_POST['dollar_amt'],$_POST['cent_amt']) ); PHP: I would like to store it as the session, and then add more items to it. Any help is appreciated!
"array_push — Push one or more elements onto the end of array" http://uk.php.net/manual/en/function.array-push.php Is that what you need?
My page is going through the first array correctly, but after that it only displays 'array' and then after that it's like it doesn't add to the array.. here is my code... <?php session_start(); if ($_SESSION['items']){ $item_array[] = $_SESSION['items']; $quantity_array[] = $_SESSION['quantities']; $dollar_amt_array[] = $_SESSION['dollar_amts']; $cent_amt_array[] = $_SESSION['cent_amts']; echo 'sessions are set'; } if ($_POST['item']){ $item_array[] = $_POST['item']; $quantity_array[] = $_POST['quantity']; $dollar_amt_array[] = $_POST['dollar_amt']; $cent_amt_array[] = $_POST['cent_amt']; $_SESSION['items'] = $item_array; $_SESSION['quantities'] = $quantity_array; $_SESSION['dollar_amts'] = $dollar_amt_array; $_SESSION['cent_amts'] = $cent_amt_array; $num_of_items = count($item_array); echo $num_of_items . '<br>'; for ($row = $num_of_items-1; $row >= 0; $row--){ echo $item_array[$row] . ' ' . $quantity_array[$row] . ' ' . $dollar_amt_array[$row] . '.' . $cent_amt_array[$row] . '<br>'; } } ?> <html> <form action="test.php" method="post"> <table> <tr> <td> Item Description: </td> <td> <input type="text" name="item"> </td> <td> Quantity </td> <td> <input type="text" name="quantity"> </td> <td> Cost: </td> <td> $<input type="text" name="dollar_amt"> .<input type="text" name="cent_amt"> </td> </tr> </table> <input type="submit"> </form> </body> </html> PHP: The url is: www.munzcomputers.com/test.php