23.04.2026 | Lothar Ferreira Neumann
sort_by_weight.php
// ...
$build['content_1'] = [
'#markup' => "content 1",
'#custom_weight_property' => 10,
];
$build['content_2'] = [
'#markup' => "content 2",
'#custom_weight_property' => 5,
];
usort($build, function ($a, $b) {
return SortArray::sortByKeyInt($a, $b, '#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).