Php-如何将多个键值数组转换为|(管道)分隔字符串
我正在处理一个项目,其中包含多个阵列操作 我有一个名为$product\u attributes的变量,它包含以下数组作为值Php-如何将多个键值数组转换为|(管道)分隔字符串,php,arrays,string,pipe,Php,Arrays,String,Pipe,我正在处理一个项目,其中包含多个阵列操作 我有一个名为$product\u attributes的变量,它包含以下数组作为值 Array ( [0] => Array ( [0] => Applications [1] => Steel; PVC; Std. Wall ) [1] => Array ( [0] => Blade E
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
使用
阵列映射
和内爆
功能的解决方案:
$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
这可能会有帮助