Created
November 29, 2016 18:38
-
-
Save guiassemany/6e353b7b7d614a98f4aef5818aa7dd66 to your computer and use it in GitHub Desktop.
Sort array keys based on another array.
This file contains hidden or 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 | |
| $unsorted = [ | |
| ['d'=> 'teste', 'c' => 'teste2', 'e' => 'teste3'], | |
| ['d'=> 'teste', 'c' => 'teste2', 'e' => 'teste3'], | |
| ['d'=> 'teste', 'e' => 'teste3', 'c' => 'teste2', 'f' => 'valor'] | |
| ]; | |
| $keys = ['c','e','d', 'f']; | |
| $sorted = []; | |
| foreach($unsorted as $key => $item){ | |
| $sorted[] = array_merge(array_flip($keys), $item); | |
| } | |
| var_dump($sorted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment