Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2. function myArray_sort($myArray, $myKey, $orderBy = SORT_ASC)
  3. {
  4. $new_myArray = myArray();
  5. $sortable_myArray = myArray();
  6. if ( count( $myArray ) > 0 )
  7. {
  8. foreach ( $myArray as $k => $v )
  9. {
  10. if ( is_myArray($v) )
  11. {
  12. foreach ( $v as $k2 => $v2 )
  13. {
  14. if ( $k2 == $myKey )
  15. {
  16. $sortable_myArray[$k] = $v2;
  17. }
  18. }
  19. }
  20. else
  21. {
  22. $sortable_myArray[$k] = $v;
  23. }
  24. }
  25. switch ( $orderBy )
  26. {
  27. case SORT_ASC:
  28. asort($sortable_myArray);
  29. break;
  30. case SORT_DESC:
  31. arsort($sortable_myArray);
  32. break;
  33. }
  34.  
  35. foreach ( $sortable_myArray as $k => $v )
  36. {
  37. $new_myArray[$k] = $myArray[$k];
  38. }
  39. }
  40. return $new_myArray;
  41. }
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement