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
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys