当前位置:网站首页>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;
}
边栏推荐
- [multithreading] the main thread waits for the sub thread to finish executing, and records the way to execute and obtain the execution result (with annotated code and no pit)
- Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?
- Jenkins installation
- JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
- C#多维数组的属性获取方法及操作注意
- Tdsql | difficult employment? Tencent cloud database micro authentication to help you
- easyExcel和lombok注解以及swagger常用注解
- Precautions for scalable contract solution based on openzeppelin
- 亚马逊云科技 Community Builder 申请窗口开启
- The position of the first underline selected by the vant tabs component is abnormal
猜你喜欢

GGPlot Examples Best Reference

Eight sorting summaries

The position of the first underline selected by the vant tabs component is abnormal

VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题

制造业数字化转型和精益生产什么关系

在连接mysql数据库的时候一直报错

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

GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

Principle of scalable contract delegatecall
随机推荐
ESP32音频框架 ESP-ADF 添加按键外设流程代码跟踪
Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement
Bedtools tutorial
解决uniapp列表快速滑动页面数据空白问题
bedtools使用教程
可昇級合約的原理-DelegateCall
Jenkins installation
基于Hardhat编写合约测试用例
亚马逊云科技 Community Builder 申请窗口开启
flutter 问题总结
ros缺少xacro的包
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
ASTParser 解析含有emum 枚举方法的类文件的踩坑记
基于 Openzeppelin 的可升级合约解决方案的注意事项
Visualization of chip SEQ data by deeptools
MySql存储过程游标遍历结果集
6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application
PX4 Position_Control RC_Remoter引入
Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R