我有2个协会。 其具有相同的结构,但只有一个ID是相同的阵列。 我需要内容从IncludeArray每次特定ID是相同添加到MainArray。
下面是阵列的样品(MainArray可以容纳多达100名以上的项目中,样品含有只有真正的内容的一部分):
$MainArray = Array
(
[0] => Array
(
[item_id] => 1
[name] => Test1
[helptxt] => Helptext for item-id 1.
[type_id] => 1 #could be the same for many other items!!
)
[1] => Array
(
[item_id] => 2
[name] => Test2
[helptxt] => Helptext for item-id 2.
[type_id] => 2 #could be the same for many other items!!
)
and a lot more Arrays
)
$IncludeArray = Array
(
[0] => Array
(
[type_id] => 1
[typetitle] => Number
[typedesc] => Description Text type_id 1
)
[1] => Array
(
[type_id] => 2
[typetitle] => Value
[typedesc] => Description Text type_id 2
)
)
所需的新的数组应该是:
$NewMainArray = Array
(
[0] => Array
(
[item_id] => 1
[name] => Test
[helptxt] => Helptext for item-id 1.
[type_id] => 1
[typetitle] => Number
[typedesc] => Description Text type_id 1
)
[1] => Array
(
[item_id] => 2
[name] => Test2
[helptxt] => Helptext for item-id 2.
[type_id] => 2
[typetitle] => Value
[typedesc] => Description Text type_id 2
)
And so on with all other items in the Array.
)
所以eachtime一个TYPE_ID在$ MainArray发现[typetitle] + [TYPEDESC]应该被添加到$ NewMainArray内容。
我的大多数测试中只有合并或刚刚添加的$ IncludeArray只有一次阵列结束。 即使我的论坛搜索不要让我一个解决方案。
该阵列是由2个独立的DB-请求,我不能参加创建(已经尝试过多次尝试)。 这涉及到不同的WHERE和AND子句,不上加入请求工作。
我希望有一个聪明的方式来获得所需的$ NewMainArray。 BTW我用PHP4和我是一个新手到PHP(至少对于这样的问题)。
非常感谢你的帮助。