如何在PHP中将数字更改为随机位置

How would I go about changing the following numbers around to a random positions in php?

Do I need to explode the numbers?

40,52,78,81,25,83,37,77

Thanks

$arr = explode(',', '40,52,78,81,25,83,37,77');
shuffle($arr);
echo implode(',', $arr);

http://ideone.com/sh2uH

So you want to shuffle the array order? Use PHP's shuffle function.

http://php.net/manual/en/function.shuffle.php

EDIT: Didn't realise your numbers were in a string. The other answer sums it up.

Assuming the numbers are in a string:

$numbers = '40,52,78,81,25,83,37,77';
$numbers = explode(',',$numbers);
shuffle($numbers);
$numbers = implode(',',$numbers);

Try something like this.

$string = "40,52,78,81,25,83,37,77";
$numbers = explode(",", $string);
shuffle($numbers);
print_r($numbers);

explode breaks the string out into an array separating entries by ,

shuffle will operate on the array by reference and put them in random order