Guest User

Untitled

a guest
Dec 15th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2. /**
  3. * Move array position
  4. *
  5. * @return array
  6. */
  7. function array_splice_assoc(&$input, $offset, $length, $replacement) {
  8. $replacement = (array) $replacement;
  9. $key_indices = array_flip(array_keys($input));
  10. if (isset($input[$offset]) && is_string($offset)) {
  11. $offset = $key_indices[$offset];
  12. }
  13. if (isset($input[$length]) && is_string($length)) {
  14. $length = $key_indices[$length] - $offset;
  15. }
  16.  
  17. $input = array_slice($input, 0, $offset, TRUE) + $replacement + array_slice($input, $offset + $length, NULL, TRUE);
  18. }
  19. function cpr_move_positin_element($which, $where, $array)
  20. {
  21. $tmpWhich = $which;
  22. $j=0;
  23. $keys = array_keys($array);
  24.  
  25. for($i=0;$i<count($array);$i++)
  26. {
  27. if($keys[$i]==$tmpWhich)
  28. $tmpWhich = $j;
  29. else
  30. $j++;
  31. }
  32. $tmp = array_splice($array, $tmpWhich, 1);
  33. array_splice_assoc($array, $where, 0, $tmp);
  34. return $array;
  35. }
Add Comment
Please, Sign In to add comment