Jump to: navigation, search

Php shuffle

From w3cyberlearnings

Contents

PHP function shuffle

This function randomizes the order of the array elements. It returns a new array with a new keys and the origional key removed. The value is as it is.

Syntax shuffle

  • array: array input
shuffle(array);

Example 1

<?php


$name = array('Taylor',
	 'Lucas',
	 'Makayla',
	 'Jennifer');

shuffle($name);

print_r($name);
?>


Output

Array
(
    [0] => Taylor
    [1] => Jennifer
    [2] => Makayla
    [3] => Lucas
)

Example 2

<?php


$score = array('Taylor'=>3,
	 'Lucas'=>2,
	 'Makayla'=>5,
	 'Jennifer'=>3);

shuffle($score);

print_r($score);
?>

Output

Array
(
    [0] => 2
    [1] => 3
    [2] => 3
    [3] => 5
)

Related Links


Navigation
Web
SQL
MISC
References