How to use php shuffle function
php shuffle function is used to rearrange the elements in the array in random order. The syntax is shuffle(array), and the parameter array is required and refers to the array to be used.
#How to use the php shuffle function?
Definition and usage
shuffle() function rearranges the elements in the array in random order.
This function assigns new key names to elements in the array, and existing key names will be deleted (see Example 1 below).
Syntax
shuffle(array)
Parameters
array Required. Specifies the array to use.
Return value: TRUE if successful, FALSE if failed.
PHP Version: 4
Change Log: As of PHP 4.2.0, the random number generator is automatically seeded.
Example 1
Rearrange the elements in the array in random order:
<?php $my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple"); shuffle($my_array); print_r($my_array); ?>
Output:
Array ( [0] => red [1] => blue [2] => green [3] => purple [4] => yellow )
Example 2
Rearrange the elements in the array in random order:
<?php $my_array = array("red","green","blue","yellow","purple"); shuffle($my_array); print_r($my_array); ?>
Output:
Array ( [0] => blue [1] => green [2] => yellow [3] => red [4] => purple )
The above is the detailed content of How to use php shuffle function. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
