Php 随机洗牌数组值
如何使用随机逻辑对数组项重新排序? 例如:Php 随机洗牌数组值,php,arrays,random,element,Php,Arrays,Random,Element,如何使用随机逻辑对数组项重新排序? 例如: $arr = array('one', 'two', 'three', 'four', 'five'); 改为: $new_arr = array('five', 'one', 'three', 'four', 'two'); 您可以使用内置的shuffle()PHP函数: <?php $arr = array('one', 'two', 'three', 'four', 'five'); shuffle($arr);
$arr = array('one', 'two', 'three', 'four', 'five');
改为:
$new_arr = array('five', 'one', 'three', 'four', 'two');
您可以使用内置的
shuffle()
PHP函数:
<?php
$arr = array('one', 'two', 'three', 'four', 'five');
shuffle($arr);
print_r($arr);
?>
Google,文字:“php数组随机”,结果:太多了。不要偷懒。而且,这个词是“随机的”,而不是“随机的”,这个词甚至不存在(但我还是喜欢它)。