I am working on one project with multiple array operations.
I have one variable called $product_attributes and it contains below array as value.
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
)
)
Now i want to convert it into | (Pipe) Separated String like below:
Applications=Steel; PVC; Std. Wall|Blade Exp.=0.29|Fits Model=153
Below is what i have tried:
$tags = implode('|',$product_attributes);
echo "Output".$tags;
But it returns output as below:
OutputArray|Array|Array|Array|Array|Array
The solution using array_map and implode functions:
$result = implode("|", array_map(function ($v) {
return $v[0] . "=" .$v[1];
}, $product_attributes));
print_r($result);
The output:
Applications=Steel; PVC; Std. Wall|Blade Exp.=0.29|Fits Model=153
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With