PHP Array Random Sorting


 

PHP Array Random Sorting

PHP Array Random Sorting, PHP provides a special function shuffle, which can be use to shuffle the elements of an array.

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...

Ads