从多个包含分号的数组中合并数据的最佳方法是什么? [英] What is the best way for combining data from multiple arrays enclosing semicolons?
问题描述
让我解释一下下面的内容吧!
Let me explain bellow practically what i have and have i need
我将在PHP,MySQL和WordPress Project中使用此数据,目前我拥有这些数据
I'll be using this data in PHP, MySQL and WordPress Project, Currently I have these data in JSON file.
array_texts:
array_texts:
Link Text 1; Link Text 2; Link Text 3
array_links
array_links
https://url1.com; https://url2.com; https://url3.com
这不限于3我有更多&
this is not limited to 3 i have more & less.
我需要最好的解决方案,以便使用MySQL从JSON到PHP / Wordpress使用海量数据(速度更快)
I need the best solution to use huge data from JSON to PHP/Wordpress with MySQL (Which ever works faster)
每个对象的预期结果 链接文本
<a href="https://url.com">Link Text</a>
以及整个组合的数组或类似内容:
and the whole combination as array or something like:
<a href="https://url1.com">Link Text 1</a>; <a href="https://url2.com">Link Text 2</a>; <a href="https://url3.com">Link Text 3</a>
推荐答案
如何使用 explode
和 implode
断开字符串,将它们与 array_map
组合在一起(手册-注意使用 null $ c $函数中的c>),然后将
foreach
设置为:
How about use explode
and implode
to break the string, combine them with array_map
(manual - notice the use of null
in the function) and foreach
as:
$array_texts = explode("; ", "Link Text 1; Link Text 2; Link Text 3");
$array_links = explode("; ", "https://url1.com; https://url2.com; https://url3.com");
$arr = array_map(null, $array_texts, $array_links);
foreach($arr as $aa) {
$az[] = '<a href="' . $aa[1] . '">' . $aa[0] . '</a>';
}
echo implode("; ", $az);
这将为您提供愿望输出
实时示例 3v4l
这篇关于从多个包含分号的数组中合并数据的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!