Thursday, 25 September 2014

shuffle in PHP

PHP shuffle() function is used to randomize the order of the elements in an array.
PHP shuffle() function assigns new keys for the elements in the array.
It returns TRUE on success, or FALSE on failure.

Syntax:

shuffle(array,sorttype)
array : Required. Specifies the array to use.

Example:

<?php
$daysarr = array( "a"=>"Sunday", "b"=>"Monday", "c"=>"Tuesday" );
shuffle($daysarr);
print_r($daysarr);
?>

O/P:

Array ( 
           [0] => Monday 
           [1] => Tuesday 
           [2] => Sunday
       )

0 comments:

Post a Comment