当前位置:网站首页>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
边栏推荐
- uni使用的一些坑
- Utf8 to STD: string and STD: string to utf8
- Rog attack
- Formal parameters, local variables and local static variables
- DWSurvey是一个开源的调查问卷系统。解决无法运行问题,修改bug。
- The QT debug version runs normally and the release version runs crash
- Some pits used by uni
- xxl-job采坑指南xxl-rpc remoting error(connect timed out)
- Hongji micro classroom | cyclone RPA's "flexible digital employee" actuator
- Arithmetic and logical operations
猜你喜欢
Pytorch deep learning practice_ 11 convolutional neural network
QSS, qdateedit, qcalendarwidget custom settings
Hongji | how does HR carry out self change and organizational change in the digital era?
第36期《AtCoder Beginner Contest 248 打比赛总结》
2-软件设计原则
Transposed convolution
C# ,类库
deep learning object detection
Differences between sea level anatomy and sea surface height anatomy
STL learning notes 0x0001 (container classification)
随机推荐
字符识别easyocr
Hongji micro classroom | cyclone RPA's "flexible digital employee" actuator
The QT debug version runs normally and the release version runs crash
The address value indicated by the pointer and the value of the object indicated by the pointer (learning notes)
IPI interrupt
STL function library
Common status codes
Jiugong magic square - the 8th Lanqiao provincial competition - group C (DFS and comparison of all magic square types)
‘EddiesObservations‘ object has no attribute ‘filled‘
Reading notes of modern methods of C language programming
Duplicate key update in MySQL
‘EddiesObservations‘ object has no attribute ‘filled‘
QT compressed folder
SQL statement simple optimization
Radar equipment (greedy)
POI exports to excel, and the same row of data is automatically merged into cells
修仙真实世界与游戏世界
Introduction to qqueue
Solid contract DoS attack
refused connection