当前位置:网站首页>If you can convert a two-dimensional array into a one-dimensional array gracefully and quickly, or convert a multi-dimensional array into a one-dimensional array
If you can convert a two-dimensional array into a one-dimensional array gracefully and quickly, or convert a multi-dimensional array into a one-dimensional array
2022-04-22 04:50:00 【Day____ Day____ Up】
How is it the simplest , Quickly expand and tile multi-dimensional arrays into one-dimensional arrays ? The following is the summary of the blogger for reference : Divided into tiles, the depth of expansion is 2 And all tiled :
Let's assume that there is an array to expand :
$arr = [
'a' => [
'a1' => 'nice100.net',
'a2' => 'good',
],
'b' => [
'b1' => [
'b11' => 'nice',
'b12' => 'like',
]
]
];
- The depth of tiling is 2:
// Method 1
$result = call_user_func_array('array_merge', $arr);
// Method 2 ( Will be faster )
$result = array_merge(...array_values($arr));
// Results output
Array
(
[a1] => nice100.net
[a2] => good
[b1] => Array
(
[b11] => nice
[b12] => like
)
)
- Tile all
// If you want to tile them all , So for multidimensional arrays , array_merge Function can't satisfy , Recursion needs to be handled
$re = [];
array_walk_recursive($arr, function ($v, $k) use (&$re) {
$re[$k] = $v;
}, $re);
// Input result , Note that if there is the same key, Then the latter will cover the former
Array
(
[a1] => nice100.net
[a2] => good
[b11] => nice
[b12] => like
)
From my blog (https://blog.nice100.net/default/45.html)
版权声明
本文为[Day____ Day____ Up]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210758105701.html
边栏推荐
- Climb the actor's name and add a link
- Es next related
- 12. Libevent loop function and exit test
- 【Selenium】Yaml数据驱动
- POJ - 2456 aggressive cows
- [selenium] basic application of unittest testing framework
- Rookie's counter attack
- Feature Engineering - feature preprocessing (normalization, standardization)
- EMO-DB 數據集的 Speech 特征提取
- Leetcode sword finger offer 51 Reverse order pair in array***
猜你喜欢

论文阅读-Access Pattern disclosure on Searchable Encryption: Ramification, Attack and Mitigation(2012)

Carina local storage selected into the CNCF cloud native panorama

Transaction isolation level and mvcc

Linear regression API

2022 question bank and answers of Shandong Province safety officer C certificate special operation certificate examination

KNN, cross validation, grid search

Solution to Chinese translation of GoLand (in case of failure to download plug-ins)

6. Comparable to JMeter Net pressure measurement tool - crank practical chapter - collecting diagnosis tracking information and how to analyze bottlenecks

Extraction de la fonction Speech de l'ensemble de données emo - DB
![[selenium] basic application of unittest testing framework](/img/17/b3d25b9eebccab37128e08bab4bd66.png)
[selenium] basic application of unittest testing framework
随机推荐
12. Libevent loop function and exit test
Boyun beyondcmp cloud management platform version 5.6 release
线程池状态+ThreadPoolExecutor
Leetcode refers to offer 43 Number of occurrences of 1 in integers 1 ~ n***
15. Bufferevent client test connection server
企业数据防泄露方案分享
【板栗糖GIS】supermap—如何為數據制造超鏈接
博云 BeyondCMP 云管理平台 5.6 版本发布
Carina 本地存储入选 CNCF 云原生全景图
Linked list Part III
goland汉化解决方法(下载插件失败的情况下)
2022 question bank and answers of Shandong Province safety officer C certificate special operation certificate examination
How to realize different values and display different colors in MATLAB
[chestnut sugar GIS] SuperMap - how to create hyperlinks for data
Return value of unique function of STL
C language simple [stack and queue] (bracket matching problem)
EMO-DB 数据集的 Speech 特征提取
一个基于.NET Core3.1的开源项目帮你彻底搞懂WPF框架Prism
JSP Hello World Chinese garbled code
Discussion on data set division