Home > Backend Development > PHP Tutorial > How to use shuffle function

How to use shuffle function

藏色散人
Release: 2023-04-05 07:22:02
Original
3839 people have browsed it

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

How to use shuffle function

php shuffle() function syntax

Function: Reorder the elements in the array in random order:

Syntax:

shuffle(array)
Copy after login

Parameters:

array required. Specifies the array to use.

Description: Return TRUE if successful, and FALSE if failed.

php shuffle() function example 1

<?php
$a = array("class" => "php中文网","name" => "西门","job" => "讲师");
shuffle($a);
print_r($a);
?>
Copy after login

Output:

Array ( [0] => 西门 [1] => php中文网 [2] => 讲师 )
Copy after login

php shuffle() function example 2

<?php
$my_array = array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow","e"=>"purple");
shuffle($my_array);
print_r($my_array);
?>
Copy after login

Output:

Array ( [0] => yellow [1] => green [2] => red [3] => purple [4] => blue )
Copy after login

This article is an introduction to the PHP shuffle function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use shuffle function. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template