Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. <?php
  2.  
  3. $myarray = array(1,0.334,-0.334,-1);
  4.  
  5. //create a copy and sort
  6. $myarray_copy = $myarray;
  7. rsort($myarray_copy);
  8. //reverses key and values
  9. $myarray_copy = array_flip($myarray_copy);
  10. //create result by using keys from sorted values + 1
  11. foreach($myarray as $val)
  12. $myarray2[] = ($myarray_copy[$val]+1);
  13. //print final array
  14. print_r($myarray2);
  15. print_r($myarray);
  16.  
  17.  
  18. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement