我知道可能这是问之前,不确定是否是在这种形式,但我确实尝试了一些重播,从我发现这里关于这一点和失败。
我有一个数组
Array
(
[0] => Array
(
[Data3] => Array
(
[id] => 5
[category] => Whiskey
[name] => Some name
[description] => description
[image] => asdf.jpg
[price] => 83.99
)
[ammount] => 1
[Data_id] => 3
)
[1] => Array
(
[Data3] => Array
(
[id] => 4
[category] => Tequila
[name] => Something Red 75cl
[description] => description
[image] => sierratequilasilver100.jpg
[price] => 92.49
)
[ammount] => 2
[Data_id] => 3
)
[2] => Array
(
[Data4] => Array
(
[id] => 3
[category] => Whiskey
[name] => Some name Gold
[description] => description
[image] => asdf.jpg
[price] => 83.99
)
[ammount] => 1
[Data_id] => 4
)
[3] => Array
(
[Data4] => Array
(
[id] => 5
[category] => Vodka
[name] => Something Blue 100 cl
[description] => description
[image] => Something.jpg
[price] => 32.44
)
[ammount] => 1
[Data_id] => 4
)
)
我所希望得到的结果是这样的:
Array
(
[0] => Array
(
[id] => 5
[category] => Whiskey
[name] => Some name
[description] => description
[image] => asdf.jpg
[price] => 83.99
[ammount] => 1
[Data_id] => 3
)
[1] => Array
(
[id] => 4
[category] => Tequila
[name] => Something Red 75cl
[description] => description
[image] => sierratequilasilver100.jpg
[price] => 92.49
[ammount] => 2
[Data_id] => 3
)
[2] => Array
(
[id] => 3
[category] => Whiskey
[name] => Some name Gold
[description] => description
[image] => asdf.jpg
[price] => 83.99
[ammount] => 1
[Data_id] => 4
)
[3] => Array
(
[id] => 5
[category] => Vodka
[name] => Something Blue 100 cl
[description] => description
[image] => Something.jpg
[price] => 32.44
[ammount] => 1
[Data_id] => 4
)
)
或者我可以使用的另一种方法是,如果我可以更改数据1,数据2,数据3等等。
可以是n数据取决于用户选择了多少产品
转换为相同的名称,例如简单的Data或Info。
例如:
Array
(
[0] => Array
(
[Info] => Array
(
[id] => 5
[category] => Whiskey
[name] => Some name
[description] => description
[image] => asdf.jpg
[price] => 83.99
)
[ammount] => 1
[Data_id] => 3
)
[1] => Array
(
[Info] => Array
(
[id] => 4
[category] => Tequila
[name] => Something Red 75cl
[description] => description
[image] => sierratequilasilver100.jpg
[price] => 92.49
)
[ammount] => 2
[Data_id] => 3
)
任何解决方案都可以。
谢谢并致以问候
4条答案
按热度按时间yqhsw0fo1#
使用以下代码获得结果:
edqdpe6u2#
我会这样做。但是,我会寻找修复为什么数据是在该结构开始。
5us2dqdw3#
您第一个选择:
Check output here
brqmpdu14#
这是最好的算法