Home > Articles


  • Print
  • + Share This

3.11 Randomizing the Elements of an Array

You want to randomize all elements in an array.


Use the shuffle() function, which changes the order of the array elements:

srand ((double)microtime()*1000000);
$some_array = range(1, 52);
// $some_array now contains numbers from 1 to 52 in random order.


The shuffle() function is extremely useful for randomizing arrays because it saves you the time of writing your own complex routine. This can be useful if, for example, you make an online poker game or dice game and want the results to be completely random.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.