我想从我的数据库中回显多维数组,我试图在 stackoverflow 中搜索,但我无法很好地实现。
这是我的数组:
Array (
[0] => Array (
[product_name] => BMW
[category_name] => Car
)
[1] => Array(
[product_name] => Jaguar
[category_name] => Car
)
[2] => Array(
[product_name] => Toyota
[category_name] => Car
)
[3] => Array (
[product_name] => Jeep
[category_name] => Car
)
[4] => Array (
[product_name] => Ducati
[category_name] => Bike
)
)
我需要将这个数组分组如下:
Array(
[0] => Array(
[category_name] => Car
[product_name] => Array(
[0] => Array(
[product_name] => BMW
)
[1] => Array(
[product_name] => Toyota
)
[2] => Array(
[product_name] => Jaguar
)
[3] => Array(
[product_name] => Jeep
)))
[1] => Array (
[category_name] => Bike
[product_name] => Array
(
[0] => Array
(
[product_name] => Ducati
)) )
然后回显到 html 列表:
汽车: - 宝马 - 丰田 - 捷豹 - 吉普
自行车: - 杜卡迪
请帮忙..谢谢
慕勒3428872
胡子哥哥