当前位置:网站首页>PHP 2D and multidimensional arrays are out of order, PHP_ PHP scrambles a simple example of a two-dimensional array and a multi-dimensional array. The shuffle function in PHP can only scramble one-dim
PHP 2D and multidimensional arrays are out of order, PHP_ PHP scrambles a simple example of a two-dimensional array and a multi-dimensional array. The shuffle function in PHP can only scramble one-dim
2022-07-02 11:48:00 【Hang Hang Dad】
php A simple example of a two-dimensional array and a multi-dimensional array
php Medium shuffle Functions can only scramble one-dimensional arrays , What's a quick and convenient way to scramble multidimensional arrays ? The manual provides
function shuffle_assoc($list) {
if (!is_array($list)) return $list;
$keys = array_keys($list);
shuffle($keys);
$random = array();
foreach ($keys as $key)
$random[$key] = $list[$key];
return $random;
}
?>
The above one is for two-dimensional arrays !
The following is an unordered method for multidimensional arrays ? As convenient and fast as possible :
function shuffle_assoc($list) {
if (!is_array($list)) return $list;
$keys = array_keys($list);
shuffle($keys);
$random = array();
foreach ($keys as $key)
$random[$key] = shuffle_assoc($list[$key]);
return $random;
}
?>
The following functions are also from php manual , Can disrupt multidimensional arrays :
/**
* Shuffles an associative array recursive
*
* @param array $array
* @return array
*
*/
function rec_assoc_shuffle($array)
{
$ary_keys = array_keys($array);
$ary_values = array_values($array);
shuffle($ary_values);
foreach($ary_keys as $key => $value) {
if (is_array($ary_values[$key]) AND $ary_values[$key] != NULL) {
$ary_values[$key] = rec_assoc_shuffle($ary_values[$key]);
}
$new[$value] = $ary_values[$key];
}
return $new;
}
边栏推荐
- Introduction to interface debugging tools
- A sharp tool for exposing data inconsistencies -- a real-time verification system
- map集合赋值到数据库
- RPA advanced (II) uipath application practice
- vant tabs组件选中第一个下划线位置异常
- 进入前六!博云在中国云管理软件市场销量排行持续上升
- 可昇級合約的原理-DelegateCall
- PowerBI中导出数据方法汇总
- HOW TO ADD P-VALUES ONTO A GROUPED GGPLOT USING THE GGPUBR R PACKAGE
- What are the methods of adding elements to arrays in JS
猜你喜欢

Redis超出最大内存错误OOM command not allowed when used memory > 'maxmemory'

Tdsql | difficult employment? Tencent cloud database micro authentication to help you

MySQL comparison operator in problem solving

6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application

亚马逊云科技 Community Builder 申请窗口开启

Cluster Analysis in R Simplified and Enhanced

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

2022年遭“挤爆”的三款透明LED显示屏

Research on and off the Oracle chain

基于Hardhat和Openzeppelin开发可升级合约(二)
随机推荐
Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
Cluster Analysis in R Simplified and Enhanced
C file and folder operation
在连接mysql数据库的时候一直报错
excel表格中选中单元格出现十字带阴影的选中效果
How to Add P-Values onto Horizontal GGPLOTS
TDSQL|就业难?腾讯云数据库微认证来帮你
PHP query distance according to longitude and latitude
ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
Amazon cloud technology community builder application window opens
ASTParser 解析含有emum 枚举方法的类文件的踩坑记
Solve the problem of data blank in the quick sliding page of the uniapp list
What are the methods of adding elements to arrays in JS
Visualization of chip SEQ data by deeptools
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
Three transparent LED displays that were "crowded" in 2022
Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?
Wechat applet uses Baidu API to achieve plant recognition
文件操作(详解!)
vant tabs组件选中第一个下划线位置异常