当前位置:网站首页>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;
}
边栏推荐
- PLC-Recorder快速监控多个PLC位的技巧
- Attribute acquisition method and operation notes of C # multidimensional array
- ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
- 2022年4月17日五心红娘团队收获双份喜报
- 进入前六!博云在中国云管理软件市场销量排行持续上升
- Esp32 audio frame esp-adf add key peripheral process code tracking
- Is the stock account given by qiniu business school safe? Can I open an account?
- PX4 Position_Control RC_Remoter引入
- 6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application
- Skills of PLC recorder in quickly monitoring multiple PLC bits
猜你喜欢
[cloud native] 2.5 kubernetes core practice (Part 2)
Principle of scalable contract delegatecall
TDSQL|就业难?腾讯云数据库微认证来帮你
Basic usage of MySQL in centos8
动态内存(进阶四)
What is the relationship between digital transformation of manufacturing industry and lean production
The computer screen is black for no reason, and the brightness cannot be adjusted.
K-Means Clustering Visualization in R: Step By Step Guide
How to Visualize Missing Data in R using a Heatmap
制造业数字化转型和精益生产什么关系
随机推荐
PX4 Position_ Control RC_ Remoter import
可升级合约的原理-DelegateCall
C file and folder operation
JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
Order by injection
How to Create a Nice Box and Whisker Plot in R
念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
Installation of ROS gazebo related packages
Some things configured from ros1 to ros2
Esp32 audio frame esp-adf add key peripheral process code tracking
Homer预测motif
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
SSRF
2022年遭“挤爆”的三款透明LED显示屏
揭露数据不一致的利器 —— 实时核对系统
PHP query distance according to longitude and latitude
Bedtools tutorial
vant tabs组件选中第一个下划线位置异常
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'