0

I have custom realization - where i can add to product items, i can get for product items like this:

<?php if(!empty($cart_item['more_product'])) :
                                    $first_array = array_slice($cart_item['more_product'],0,4);
                                    $second_array = array_slice($cart_item['more_product'],4);
                                ?>
                            <div class="products__includes">

                                <div class="products__includes__btn active">
                                    Set includes
                                </div> 
                                <div class="products__includes__wrap">
                                    <div class="products__includes__inner">
                                        <table>
                                            <tbody>
                                        <?php foreach($first_array as $piece): ?>
                                            <tr>
                                                <th><?php echo $piece['title'];?></th>
                                                <th><?php echo $piece['count'];?></th>
                                            </tr>
                                        <?php endforeach;?>
                                            </tbody>
                                        </table>
                                        <?php if(!empty($second_array)):?>
                                            <table>
                                                <tbody>
                                                <?php foreach($second_array as $piece): ?>
                                                    <tr>
                                                        <th><?php echo $piece['title'];?></th>
                                                        <th><?php echo $piece['count'];?></th>
                                                    </tr>
                                                <?php endforeach;?>
                                                </tbody>
                                            </table>
                                        <?php endif; ?>


                                    </div>  

                                </div>

                            </div>
                            <?php endif; ?>

i need get this all in order, how i can do?

1 Answer 1

1

Put a look here for all sort possibility with an array: https://www.php.net/manual/fr/array.sorting.php

Look here for array_reverse if you want to reverse the list: https://www.php.net/manual/en/function.array-reverse.php

EDIT: But maybe you want to manually sort your items?

Not the answer you're looking for? Browse other questions tagged or ask your own question.