JDT

 

FREE Downloads
Articles
Tutorials

 

Using the PHP shuffle() function


The PHP shuffle() function is useful if, for example, you want to extract random items from a database.

Here is a very simple script showing how to use shuffle().

<?php

$name = array('John', 'Michael', 'Steven', 'Angela', 'Henry', 'Stuart', 'Peter', 'Nathalie', 'Susan', 'Maria');

shuffle($name);

print $name[0];
?>

This script displays one name from those contained in the array called $name.

The names are initially loaded into the array, they are then shuffled using the shuffle() function, and then the first item in the array is printed to the screen.

If you go to www.computernostalgia.net, you can see an example of how the shuffle() command is being used to randomly display photos (on the home page) from a database.

If you want the code for this, send me an email (john at dixondevelopment.co.uk) and I'll send it to you.







Go back to PHP Tutorials home page

Go back to Tutorials home page



Earnings Tracker is John Dixon Technology's FREE open source accounting / bookkeeping software tool.

Aimed at contractors and freelancers, Earnings Tracker enables you to perform bookkeeping and accounting tasks, helping you to keep track of your company's earnings and outgoings.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

Need free accounting software
 


JDT

Copyright Notice for John Dixon Technology Ltd

Privacy Statement

Terms & Conditions