Posted By

coggla on 01/20/08


Tagged

arrays


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

heinz1959
bsisco


Arrays


 / Published in: PHP
 

A few array functions

  1. // Make an array with unique values from a comma delimited string
  2. $array = array_unique(explode(',',$string));
  3.  
  4. // Compare array1 to array2 and remove common values
  5. $array = array_diff($array1, $array2);
  6.  
  7. // Randomise order of the array elements
  8. shuffle($array);
  9.  
  10. // Sort array in natural order then reverse
  11. natsort($dl);
  12. $dl = array_reverse($dl, false);
  13.  
  14. Numeric arrays
  15.  
  16. // Make an array over a number range
  17. $array = range(1,100);
  18.  
  19. // Make an array over a number range stepped by 10
  20. $array = range(1,100,10);

Report this snippet  

You need to login to post a comment.