The problem is the following: there is a need in the foreach loop to check the value of the array at the previous iteration with the current one. For example: there is a cycle: <?php foreach ($_SESSION['orders'] as $orders): ?> With the help of it I fill in some field with data: <?php echo $orders["OrderID"];?> , Now I need to write a condition that checks this (current) value of $orders["OrderID"] with the value of $orders["OrderID"] on the previous iteration - how to do it?

    1 answer 1

    You can save the previous value in a separate variable at the end of the iteration, for example, in this way

     <?php $prev_order_id = null; foreach ($_SESSION['orders'] as $orders) { ... if ($orders["OrderID"] != $prev_order_id) echo $orders["OrderID"]; ... // В конце цикла сохраняем текущее значение OrderID $prev_order_id = $orders["OrderID"]; }