What does php shuffle mean?

青灯夜游
Release: 2023-03-11 10:06:01
Original
2750 people have browsed it

In PHP, the Chinese meaning of shuffle is "shuffle". This function can randomly disrupt the array and rearrange the elements in the array in random order. The syntax format is "shuffle(array)". The shuffle() function assigns new keys to elements in the array, and existing keys are deleted.

What does php shuffle mean?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

What does php shuffle mean?

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

The shuffle() function will not only randomly shuffle the array, but also delete the original key names of the array and re-create new key names. The syntax format of the function is as follows:

shuffle(array)
Copy after login

where array is the array to be operated on. The function returns TRUE if it succeeds and FALSE if it fails.

Tip: The shuffle() function is only applicable to the first dimension of the array, and is invalid for dimensions other than the first dimension in multi-dimensional arrays.

Example:Use the shuffle() function to disrupt the order of the array

 '红色', '颜色2' => '黄色', '颜色3' => '蓝色', '颜色4' => '紫色'); echo '
'; echo '数组打乱顺序前:'; print_r($info); echo '数组打乱顺序后:'; shuffle($info); print_r($info); ?>
Copy after login

Output:

数组打乱顺序前:Array ( [颜色1] => 红色 [颜色2] => 黄色 [颜色3] => 蓝色 [颜色4] => 紫色 ) 数组打乱顺序后:Array ( [0] => 蓝色 [1] => 红色 [2] => 黄色 [3] => 紫色 )
Copy after login

With the array_rand() function Similarly, the shuffle() function can also be used to generate random verification codes. The sample code is as follows:

'; echo verCode().'
'; echo verCode().'
'; ?>
Copy after login

The running results are as follows:

WLmj ngqO EolQ
Copy after login

Note: Because the shuffle() function randomly changes the array Disruption, so the results of each execution will be different.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does php shuffle mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!