PHP shuffle() 函数

PHP 教程 · 2019-01-22 22:43:26

实例

把数组中的元素按随机顺序重新排列:

<?php
$my_array = array("red","green","blue","yellow","purple");

shuffle($my_array);
print_r($my_array);
?>

定义和用法

shuffle() 函数把数组中的元素按随机顺序重新排列。

该函数为数组中的元素分配新的键名,已存在的键名将被删除(参见下面的实例 1)。

语法

shuffle(array)

参数 描述
array 必需。规定要使用的数组。

技术细节

返回值: 如果成功则返回 TRUE,如果失败则返回 FALSE。
PHP 版本: 4+
更新日志: 自 PHP 4.2.0 起,随机数生成器会自动播种。

更多实例

实例 1

把数组中的元素按随机顺序重新排列:

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

shuffle($my_array);
print_r($my_array);
?>

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

The Intersectional Internet

The Intersectional Internet

Safiya Umoja Noble、Brendesha M. Tynes / Peter Lang Publishing / 2016

From race, sex, class, and culture, the multidisciplinary field of Internet studies needs theoretical and methodological approaches that allow us to question the organization of social relations that ......一起来看看 《The Intersectional Internet》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具