Home  >  Article  >  Backend Development  >  How to use shuffle function

How to use shuffle function

藏色散人
藏色散人Original
2019-02-12 10:51:413716browse

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)

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);
?>

Output:

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

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);
?>

Output:

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

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!

Statement:
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
Previous article:How to use list functionNext article:How to use list function