Last active
August 2, 2022 06:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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