Advertisement
Guest User

usort-example

a guest
Sep 26th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. <?php
  2. function list_cmp($a, $b) {
  3. global $order;
  4.  
  5. foreach ($order as $key => $value) {
  6. if ($a == $value) {
  7. return 0;
  8. }
  9.  
  10. if ($b == $value) {
  11. return 1;
  12. }
  13. }
  14. }
  15.  
  16. $order[0] = 1;
  17. $order[1] = 3;
  18. $order[2] = 4;
  19. $order[3] = 2;
  20.  
  21. $array[0] = 2;
  22. $array[1] = 1;
  23. $array[2] = 3;
  24. $array[3] = 4;
  25. $array[4] = 2;
  26. $array[5] = 1;
  27. $array[6] = 2;
  28.  
  29. usort($array, "list_cmp");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement