php - Array Combination need as like below
问题描述
I have 2 arrays $finalTitle
and $finalDescription
i have used array_merge
and create main array as $finalResult
and output as below
[
{
title: "ABC's Script"
},
{
title: "DEF's Script"
},
{
title: "GHI's Script"
},
{
title: "JKL's Script"
},
{
description: "My Name is ABC, I am living in Rajkot, I can able to speak English Language."
},
{
description: "My Name is DEF, I am living in Surat, I can able to speak Hindi Language."
},
{
description: "My Name is GHI, I am living in Vadodara, I can able to speak Tamil Language."
},
{
description: "My Name is JKL, I am living in Ahmedabad, I can able to speak Gujarati Language."
}
]
I want array result as below in final output. I want title
and description
in single array instead of different array name.
[
{
title: "ABC's Script",
description: "My Name is ABC, I am living in Rajkot, I can able to speak English Language."
},
{
title: "DEF's Script",
description: "My Name is DEF, I am living in Surat, I can able to speak Hindi Language."
},
{
title: "GHI's Script",
description: "My Name is GHI, I am living in Vadodara, I can able to speak Tamil Language."
},
{
title: "JKL's Script",
description: "My Name is JKL, I am living in Ahmedabad, I can able to speak Gujarati Language."
}
]
解决方案
Rather than merging the two arrays, could you not do a nested for loop so the data at each point in the array is returned then concatenate the result?
I = 0;
j = 0;
For (i = 0; 0 < finalTitle.length; I++){
For (j = 0; 0 < finalDescription.length, I++) {
finalTitle + ‘/n’ + finalDescription
}
}
推荐阅读
- reactjs - API 未返回正确的 JSON (react/express/axios)
- javascript - 将数组传递给函数 - PG 和 NodeJS
- angular - 来自 web api 2 的响应类型以及如何在 Angular 6 中处理它们
- datetime - 在 golang 中解析日期
- python - 一种在 Python 中向 contextvars 添加类型的方法
- matlab - BFGS 准牛顿算法不计算步长
- typo3 - TYPO3 异常 #1294587217:从 6.2.6 升级到 7.6.20 时
- javascript - 打开新标签或窗口,而不是弹出角度 2
- angular - 角度库安装对等依赖问题
- python - 如何找到一个独特的 HTML 元素?