php - Storing a multidimensional array from another array and calling it in a foreach loop -
I have a shopping cart build problem, most code is working, not just the last part for each loop Go I believe the problem is some kind of array that is being overwritten.
A quick overview of what's happening A shop item foreachloop (To avoid confusion I would call it for 1) Option, the array containing information about each FOR1 item is created only on a submit button, Because this is the time when an item is added to the car. The data needs to be stored in one session. (* Start session function is already called at the top of the page) The shopping cart then detects that an item has been added to the session array and displays it accordingly. After this call is called through the call, although many other items are in the $ $ _SESSION ["item"] array in the $ forwarding loop (FOR2). This code works to display the item selected by the submit_1 button and excluding the entire session (* ie Page coming back $ $ ["item"] remains in the array). Although it only displays 1 item when the button is clicked again, or clicked for any other shop item, it only displays that item and adds no new item for the first two functions . I assume that this issue is that the array is overwritten each time the button is clicked. Or have I misunderstood the functionality of the submit button, since all items use the submit_1 tags in which case how do I create a new submit button to be dynamically pressed every time? ** I also have a removable commodity function that successfully removes $ item_resire which removes the array item so that the shopping cart is empty again. Update After the answer given below, the extra step you want to add is the foreign loop inside the second foreach loop. As soon as. {Foreach ($ _ session ['item'] as the $ key) {foreach (dollar's key as dollar list) {echo $ list ["i_color"]; Echo $ list ["i_range"]; }} Try this:
if (isset ($ _ POST ["submit_1"])) {$ color = $ _POST ['color_select ']; $ Size = $ _POST ['size_select']; $ Value = $ _POST ['value']; $ Range = $ _POST ['Category']; $ Item_array = array (0 = & gt; array ('i_color' = & gt; $ color, 'i_size' = & gt; $ size, 'i_price' = & gt; $ value, 'i_range' = & gt; $ Range)); $ _SESSION ["items"] = $ item_array; }
if (empty ($ _ session ["item"])) {"ebb is empty"; } Else {foreach ($ _ session ['items'] as the $ key) {echo $ key ["i_range"]; // It really is inside a style device $ key ["i_color"]; // This is actually inside the styled divide}}
(Isset ($ _ POST ["submit_1"])) {$ color = $ _POST ['color_select']; $ Size = $ _POST ['size_select']; $ Value = $ _POST ['value']; $ Range = $ _POST ['Category']; $ Item_array = array ('i_color' = & gt; $ color, 'i_size' => $ size, 'i_price' = & gt; $ value, 'i_range' = & gt; $ range); $ _SESSION ["items"] [] = $ item_array; }
Comments
Post a Comment