Home Tutorial Php Phpbasics PHP Array Random Sorting

 
 

Share on Google+Share on Google+
PHP Array Random Sorting
Posted on: October 22, 2009 at 12:00 AM
Advertisement
PHP Array Random Sorting, PHP provides a special function shuffle, which can be use to shuffle the elements of an array.

PHP Array Random Sort

PHP provides another kind of sorting which is called Random Sorting,  in PHP shuffle() is used to sort in this manner. This function shuffles an array.

Small description of shuffle function is as follows:

General Format Boolean shuffle(array $array)
Parameters array: the array to be sorted
Return Value True/False

Example 1:

<?php

$array=array(11,3,85);

shuffle($array);

while($val=each($array))

{

echo $val['key'];

echo '=>';

echo $val['value'].'<br/>';

}

?>

Output (The output will keep changing after pressing refresh/F5 button):

First Instance:

0=>85
1=>3
2=>11

Second Instance:

0=>85
1=>11
2=>3

Third Instance:

0=>11
1=>85
2=>3

And so on...

Advertisement

Related Tags for PHP Array Random Sorting:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 22, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com