Current Location: Home> Function Categories> shuffle

shuffle

Disrupt the array
Name:shuffle
Category:Array
Programming Language:php
One-line Description:Breaking the array.

Definition and usage

shuffle() function rearranges the elements in the array in a random order.

This function assigns new key names to elements in the array. Already key names will be deleted (see Example 2 below).

Example

Example 1

Reorder the elements in the array in a random order:

 <?php
$my_array = array ( "red" , "green" , "blue" , ​​"yellow" , "purple" ) ;

shuffle ( $my_array ) ;
print_r ( $my_array ) ;
?>

Try it yourself

Example 2

Rearrange elements in the array in a random order:

 <?php
$my_array = array ( "a" => "red" , "b" => "green" , "c" => "blue" , ​​"d" => "yellow" , "e" => "purple" ) ;

shuffle ( $my_array ) ;
print_r ( $my_array ) ;
?>

Try it yourself

grammar

 shuffle ( array )
parameter describe
array Required. Specifies the array to be used.
Similar Functions
Popular Articles