1
I got the following array
:
Array
(
[0] => Array
(
[0] =>
)
[1] => Array
(
[0] => Cor
[1] => Azul
)
[2] => Array
(
[0] => Peso
[1] => 100kg
)
[3] => Array
(
[0] => Espessura
[1] => 10cm
)
[4] => Array
(
[0] =>
)
[5] => Array
(
[0] => Cor
[1] => Azul
)
[6] => Array
(
[0] =>
)
[7] => Array
(
[0] => Cor
[1] => adg
)
[8] => Array
(
[0] => Peso
[1] => gadg
)
[9] => Array
(
[0] =>
)
[10] => Array
(
[0] => Cor
[1] => Preto
)
[11] => Array
(
[0] => Espessura
[1] => 325
)
)
and need to be grouped as follows:
Array
(
[Cor] => Array
(
[0] => Azul
[1] => adg
[2] => Preto
)
[Peso] => Array
(
[0] => 100kg
[1] => gadg
)
[Espessura] => Array
(
[0] => 10cm
[1] => 325
)
)
What would be the best way to achieve this result in php
?
How is this generated array? Depending on how it is, it will be better to modify its creation than just adapt it. By the way, what you have tried to do?
– Woss
What is the rule?
– rray
Good morning Anderson, it would be while ($Row = mysqli_fetch_assoc($result)){ $descri = $Row['product description']; //ex. $descri = " - Color: Blue - Thickness: 10cm"; $test = explode(' - ', $descri); foreach ($test as $key => $value) { if ($test != '') { $teste2 = explode(': ', $value,2); $arr_test[] = $teste2; }; }; };
– Samuel Arna