php - merge array values - PHP
问题描述
I have two arrays:
First:
Array
(
[0] => Catalog No.:
[1] => H-B No.
)
Second array:
Array
(
[0] => Array
(
[0] => GG
[1] => 692
)
[1] => Array
(
[0] => VV
[1] => 693
)
)
I want o to merge them into one array to get this:
Array
(
[0] => Array
(
[0] => Catalog No.: GG
[1] => H-B No. 692
)
[1] => Array
(
[0] => Catalog No.: VV
[1] => H-B No. 693
)
)
I tried with array merge, but that works with keys and values, I want to merge only values from this two arrays into one, any help?
解决方案
<?php
$first = ['Catalog No.:', 'H-B No.'];
$second = [['GG', 692],['VV', 693]];
$result = [];
foreach ($second as $key => $values) {
foreach ($values as $number => $value) {
if (!isset($first[$number])) {
continue;
}
$result[$key][] = $first[$number] . ' ' . $value;
}
}
var_dump($result);
推荐阅读
- netsuite - SuiteScript 1.0 - 自动将客户押金应用于发票
- datatables-1.10 - 空白行/带有 YADCF 数据表的数据
- javascript - GraphQL:包装外部api没有结果
- python - 在 Windows 平台上使用 Python 或 Node.js 将多页 .TIF 图像文件转换为 PDF 格式
- android - android将数组组合到循环中
- python - 为什么 Pandas read_excel 函数在 Pyinstaller .exe 中返回错误,但在 Python 解释器下没有?
- java - Java - java.io.NotSerializableException:net.sourceforge.jtds.jdbc.JtdsConnection
- angular - 在 Ionic 框架中使用 Chart.js 和 jQuery
- tensorflow - 即使队列运行器已经启动,Tensorflow session run() 也会挂起,为什么?
- c# - 如何在c#中设置给定格式的日期时间