Sort render array by custom weight property
The output looks like this:
content 2
content 1
Just a hint:
The custom weight system controls the display order of elements, where lower weight values appear earlier, as shown in the example: content_2 (with weight 5) is rendered before content_1 (with weight 10).
Issue:
You would like to order elements of an array for rendering based on a custom weight value.
Solution:
The code assigns a custom weight property to each element in an array and then sorts the array using a custom sorting function based on these weights. Here is the link to the documentation of the function: https://www.php.net/manual/en/function.uasort.php
The Drupal SortArray class is documented here: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Utility%21SortArray.php/class/SortArray/11.x