# 问题内容:

I’ve an array , suppose this :

``````\$a=array("a","b","c","d","e");
``````

I want to make items in my array get randomize , I want to randomize the items inside /. for example I get this after ward :

``````\$a=array("d","a","b","e","c");
``````

I tried to use shuffle but it doesn’t do what I want

How can I make my array randomize ?

## 问题评论:

How are you using `shuffle`? Note that it shuffles the array in-place, so you shouldn’t assign the result to anything.
Edit; `shuffle(\$a); var_dump(\$a);` 3v4l.org/LonC5
try this … i think its basically the same thing.
From the `shuffle()` page: “This function shuffles (randomizes the order of the elements in) an array.”

# 答案:

## 答案1:

used `shuffle` function

``````  \$a=array("a","b","c","d","e");

shuffle(\$a);
print_r(\$a);
``````

for more details about `shuffle` read Documentation

## 答案2:

Please use the shuffle function. Reference: http://php.net/manual/en/function.shuffle.php

``````\$a=array("a","b","c","d","e");

shuffle(\$a);
print_r(\$a);
``````

## 答案3:

shuffle() you just need to pass your array in shuffle function.

``````<?php
\$a=array("a","b","c","d","e");

shuffle(\$a);
print_r(\$a);
?>
``````

## 原文地址：

https://stackoverflow.com/questions/47752506/php-how-to-randomizing-items-in-array

Tags:,