【发布时间】:2017-03-01 16:26:35
【问题描述】:
我有这样的类别数组,我想将相同的值(如 1 和 0 索引值等)合并到另一个新数组中,这怎么可能。
数组
(
[0] => 数组
(
[id] => 29
[父ID] => 0
[serviceName] => 头发
[parentServiceImg] => 7ffb7f5aa2a210ba927e9de64ef17f93.jpeg
[子类别] => 数组
(
[id] => 30
[parentId] => 29
[serviceName] => 爆出
[子类别] => 数组
(
[id] => 31
[parentId] => 30
[serviceName] => 添加客户接发和样式
[子类别] => 数组
(
[id] => 49
[父ID] => 31
[serviceName] => 发型颜色
[服务价格] => 100
)
)
)
)
[1] => Array
(
[id] => 1
[parentId] => 0
[serviceName] => Makeup
[parentServiceImg] => e00d3576847fef9f717d1de2647ed954.jpeg
[subCategory] => Array
(
[id] => 2
[parentId] => 1
[serviceName] => Special Event Makeup
[subCategory] => Array
(
[id] => 3
[parentId] => 2
[serviceName] => Add Airbrush
[servicePrice] => 232
)
)
)
[2] => Array
(
[id] => 1
[parentId] => 0
[serviceName] => Makeup
[parentServiceImg] => e00d3576847fef9f717d1de2647ed954.jpeg
[subCategory] => Array
(
[id] => 6
[parentId] => 1
[serviceName] => Photoshot Makeup
[subCategory] => Array
(
[id] => 7
[parentId] => 6
[serviceName] => Add Airbrush
[servicePrice] => 8
)
)
)
[3] => Array
(
[id] => 1
[parentId] => 0
[serviceName] => Makeup
[parentServiceImg] => e00d3576847fef9f717d1de2647ed954.jpeg
[subCategory] => Array
(
[id] => 2
[parentId] => 1
[serviceName] => Special Event Makeup
[subCategory] => Array
(
[id] => 4
[parentId] => 2
[serviceName] => Add Lashes
[servicePrice] => 6
)
)
)
[4] => Array
(
[id] => 29
[parentId] => 0
[serviceName] => Hair
[parentServiceImg] => 7ffb7f5aa2a210ba927e9de64ef17f93.jpeg
[subCategory] => Array
(
[id] => 2
[parentId] => 1
[serviceName] => Special Event Makeup
[subCategory] => Array
(
[id] => 47
[parentId] => 29
[serviceName] => Wedding Day Mother of the Bride / Mother of the Groom Hair Touch Ups
[servicePrice] => 5
)
)
)
)
我想使用 php 将 0 索引值与 4 索引值合并并获得新数组的 0 索引和 1 到 3 索引值合并并获得新数组中的 1 索引。我需要帮助。谢谢。
【问题讨论】:
-
您最好向我们展示您希望生成的数组是什么样子的示例。
-
还有一些代码来展示你需要为自己做什么
-
我想要这样的新数组
-
好的,我试着解释我想要什么,在我的第一个数组中,0 索引和 4 索引服务名称头发和子类别不同,所以我想将这些子类别数组合并到新数组中的一个 0 索引中像 Hair->subCategory->array('0'=>array('id'=>30),'1'=>array('id'=>2)) 这样的。谢谢
-
如果您需要帮助,请点击此处。但是你必须描述需要什么。人们不应该为你编写代码但是如果他们必须猜测你想要什么以及应该用来从头到尾得到什么标准,他们就不太可能这样做
标签: php codeigniter