gpt4 book ai didi

Php - 如何将多个键值数组转换为 | (管道)分隔字符串

转载 作者:可可西里 更新时间:2023-11-01 00:55:55 28 4
gpt4 key购买 nike

我正在处理一个包含多个数组操作的项目。

我有一个名为 $product_attributes 的变量,它包含以下数组作为值。

Array
(
[0] => Array
(
[0] => Applications
[1] => Steel; PVC; Std. Wall
)

[1] => Array
(
[0] => Blade Exp.
[1] => 0.29
)

[2] => Array
(
[0] => Fits Model
[1] => 153
)
)

现在我想把它转换成| (管道)分隔字符串如下所示:

Applications=Steel; PVC; Std. Wall|Blade Exp.=0.29|Fits Model=153

以下是我尝试过的:

$tags = implode('|',$product_attributes);
echo "Output".$tags;

但它返回如下输出:

OutputArray|Array|Array|Array|Array|Array

最佳答案

使用array_mapimplode 函数的解决方案:

$result = implode("|", array_map(function ($v) {
return $v[0] . "=" .$v[1];
}, $product_attributes));

print_r($result);

输出:

Applications=Steel; PVC; Std. Wall|Blade Exp.=0.29|Fits Model=153

关于Php - 如何将多个键值数组转换为 | (管道)分隔字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43777490/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com