Skip to content

Instantly share code, notes, and snippets.

@mborodov
Last active August 2, 2022 06:53
Show Gist options
  • Save mborodov/ce16582469bf6086472193d991b06966 to your computer and use it in GitHub Desktop.
Save mborodov/ce16582469bf6086472193d991b06966 to your computer and use it in GitHub Desktop.
Sort the elements in the array. The first elements will be those without a value in the key, then those with a value.
<?php
$flatList = [
[
'id' => '3',
'parentId' => '1',
'parentSku' => ''
],
[
'id' => '2',
'parentId' => '1',
'parentSku' => ''
],
[
'id' => '1',
'parentId' => '',
'parentSku' => ''
]
];
uasort($flatList, function($node) {
return empty($node['parentId']) ? -1 : 1;
});
// Result is here http://joxi.ru/v29JwzZt47WkvA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment