当前位置:网站首页>Split and merge multiple one-dimensional arrays into two-dimensional arrays
Split and merge multiple one-dimensional arrays into two-dimensional arrays
2022-04-23 05:44:00 【fusheng-fate】
Record the data splitting problems encountered in your work .
Scene one :
The structure of one-dimensional array is [value,value … ,value];
$arr1 = array(' Zhang San ',' Li Si ',' Wang Wu ');
$arr2 = array(18,19,20);
$arr3 = array('man','man','women');
<?php
$arr1 = array(' Zhang San ',' Li Si ',' Wang Wu ');
$arr2 = array(18,19,20);
$arr3 = array('man','man','women');
$arr4 = array_map(function($a,$b,$c){
return [$a,$b,$c];
},$arr1,$arr2,$arr3);
print_r($arr4)
?>
Running results :
Array
(
[0] => Array
(
[0] => Zhang San
[1] => 18
[2] => man
)
[1] => Array
(
[0] => Li Si
[1] => 19
[2] => man
)
[2] => Array
(
[0] => Wang Wu
[1] => 20
[2] => women
)
)
Scene two : The data structure of one-dimensional array is key =>[value1,value2,…,value3];
This is the front desk input Medium name Property is an array , For example, insert multiple pieces of data , Split the data when receiving in the background .
<input type='text' name='productNo[]' />
<input type='text' name='productName[]' />
<input type='text' name='incentiveStandard[]' />
<input type='text' class='withdrawTime' name='effectiveDateStart[]' />
<input type='text' class='withdrawTime' name='effectiveDateEnd[]' />
'name' => array(' Zhang San ',' Li Si ',' Wang Wu '),
'age' => array(18,19,20),
'sex' => array('man','man','women')
<?php
$data =array(
'name' => array(' Zhang San ',' Li Si ',' Wang Wu '),
'age' => array(18,19,20),
'sex' => array('man','man','women')
);
$arr = [];
$i = 0;
foreach ($data as $k1 => $v1){
$j = 0;
foreach ($v1 as $k2 => $v2){
$arr[$j][$k1] = $v2;
$j++;
}
$i++;
}
print_r($arr)
?>
Running results :
Array
(
[0] => Array
(
[name] => Zhang San
[age] => 18
[sex] => man
)
[1] => Array
(
[name] => Li Si
[age] => 19
[sex] => man
)
[2] => Array
(
[name] => Wang Wu
[age] => 20
[sex] => women
)
)
版权声明
本文为[fusheng-fate]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230539252712.html
边栏推荐
- 3d slicer中拉直体的生成
- Markdown syntax support test
- Cmake basic tutorial (39) pkgconfig
- Generation of straightening body in 3D slicer
- DWSurvey是一个开源的调查问卷系统。解决无法运行问题,修改bug。
- catkin_package到底干了什么
- OSI层常用协议
- Frequently asked interview questions - 1 (non technical)
- Strategy for improving the conversion rate of independent stations | recovering abandoned users
- qt. qpa. plugin: Could not find the Qt platform plugin “xcb“ in ““
猜你喜欢

AcWing 836. Merge set (merge set)

Cross platform packaging of QT packaging program

QT displays the specified position and size of the picture

SQL statement simple optimization

2-軟件設計原則

2-软件设计原则

Intel SGX preliminary learning and understanding notes (continuously updated)

基于ssm 包包商城系统

C language - Spoof shutdown applet

Hongji | how does HR carry out self change and organizational change in the digital era?
随机推荐
弘玑Cyclone RPA为国金证券提供技术支撑,超200个业务场景实现流程自动化
xxl-job采坑指南xxl-rpc remoting error(connect timed out)
Hotkeys, interface visualization configuration (interface interaction)
Some pits used by uni
Common protocols of OSI layer
Several examples of pointer transfer, parameter transfer, value transfer, etc
Flutter 新一代圖形渲染器 Impeller
Idea plug-in --- playing songs in the background
数据安全入门产品——数据库审计系统详解
Breadth first search topics (BFS)
Shell instruction learning 1
poi生成excel,插入图片
STD:: String implements split
Add days to date
open3d材质设置参数分析
Summary of redis classic interview questions 2022
Dwsurvey is an open source questionnaire system. Solve the problem that cannot be run and modify the bug.
poi导出excel,行相同数据自动合并单元格
Common status codes
C language - Spoof shutdown applet