Ordered score from A to Z

Asked

Viewed 55 times

0

I have a query, which I imagine is in object-oriented php, which in my case I’m at the beginning of studies(I know I’m late).

I have a platform Xtech, and at the time of display of some features, I have the following code

{% if product.properties|count > 0 %}
                        <div class="clearfix">
                            {% for prop in product.properties %}
                                {% if properties_flatten[prop.id].image is not empty %}
                                    <img src="{{ host_url("uploads/images/small/" ~ properties_flatten[prop.id].image) }}">
                                {% else %}
                                    <h5>{{ properties_flatten[prop.id].excerpt }} {{ properties_flatten[prop.id].name }}</h5>
                                {% endif %}

                            {% endfor %}
                        </div>
{% endif %}

This code displays the product features, Color: White, Black, Blue, Red.

I would like to alphabetize the result.

Blue, White, Black.

But I don’t know how to do that in this kind of object orientation.

Please if anyone knows and can help.

I’m sorry if I’m talking nonsense.

Thank you

  • 1

    Hello. I don’t have enough reputation to comment. Why not sort the query directly in your database? So you wouldn’t have the trouble of selecting the information, then sort it in your code. Let the database manage it for you.

  • I don’t know this syntax, so I really have no idea of the tech used there, but in many frameworks, the object comes with methods to help with that, an example would be in the foreach that you run the prop, call something in the style prop.orderBy('desc'). If you know what this technology is, it will help. Suddenly a link to documentation.

  • 1

    Alias, product.properties.groupBy('desc')

  • @Daviddias - thank you, I will analyze. I thank you for the prompt reply.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.