Home >Backend Development >PHP Tutorial >How to combine two PHP two-dimensional arrays
This article mainly shares with you the first merging method: merging an array through the array_merge method given by PHP's array API. I hope it can help everyone.
Recommended manual:php complete self-study manual
Code:
$a = array(array("1","2"),array("3","4")); $b = array(array("a","b"),array("c","d")); $c = array_merge($a,$b); print_r($c);
Result:
After the combination of these methods, the b array is appended to the a array.
Recommended related articles:
1.How to delete duplicate elements in a two-dimensional array in PHP? (Pictures + Video)
2.What are the ways to merge two arrays in PHP
Related video recommendations:
1.Dugu Jiujian (4)_PHP video tutorial
Second merging method:
Merge arrays through foreach loop
Code:
<?php $a = array(array("1","2"),array("3","4")); $b = array(array("a","b"),array("c","d")); foreach($a as $key=>$vo){ $list[] = array_merge($vo,$b[$key]); } print_r($list);
Result:
After merging this method, it becomes array b inserted into array a.
Related recommendations:
Analysis of similarities and differences between three methods of php array merging
About PHP multi-dimensional array merging and sorting functions Detailed explanation
The above is the detailed content of How to combine two PHP two-dimensional arrays. For more information, please follow other related articles on the PHP Chinese website!