PHP search array and add content on position where id's are equal -


I have 2 ascock structures containing the same structure, but only one ID is identical. I need to add content to the menu array at the same time as the specific ID of the array included in it.

Here is a sample of the array (Menare can catch up to 100 items or more, only one part in the sample is the real content):

$ MainArray = Array ([0] = & gt; Array ([item_id] = & gt; 1 [name] => Test1 [helptxt] => item-id 1. [type_id] => 1 # Many other items Can be similar to !!) [1] = & gt; Array ([item_ID] => 2 [name] => test2 [helpcut] = & gt; item-id support text 2 . [Type_id] = & gt; 2 # can be similar to many other items !!) and many more arrays) $ IncludeArray = Arr Ay ([0] = & gt; Array ([type_id] => 1 [typetitle] = & gt; number [typedesc] => description text type_id 1) [1] => array ([type_id] = & Gt; 2 [typetitle] = & gt; value [typedes c] = & gt; should be the desired new array:
  $ NewMainArray = Array ([0] => array ( [Item_id]) [=] [type] = & gt; 1 [typetitle] => number [typed] => description text type_add1) [= 1] [=] = & gt; 1 [Name] => Test [Helpcut] => 1] = & gt; Help text for Aare ([item_ID] => 2 [name] = & gt; test2 [helpcut] => item-id2. [Type IID] => 2 [typetitle] = & Gt; value [typedesc] = & gt; description text type_ id2) and so on with all other items in the array.)  

So every time a type_ id $ is found in MainArray [ Typetitle] + [typedesc]] should be added to $ NewMainArray.

After most of my trial ends, the arrays are merged only or just add $ IncludeArray only once, even my forum search can not be found for resolution.

ARAE 2 has been created from 2 different DB-requests, which I could not join (several attempts had already been attempted). It is related to different WHERE and streams, which do not work on a join request.

I hope that there is a great way to get the desired $ NewMainArray. BTW I use PHP4 and I am a newbie for PHP (at least for this kind of problem).

Thank you very much for your help.

Try it:

  / ** * Match the ID value By eating food data, simulating relational table behavior. * Works with Single Nested Array * * @ Author Joel A. Valerial Bertoldi * * @ Ultimate $ Source Array Source Array * @ Ultimate $ include_to_row Array line where we will submit the associated data I * @ Ultimate $ Match String Unique ID Field Name. * * @Renturn Array row contains * / function with data associated with the formare ($ source, $ included_to_o, $ match) {foreach (source $ $ as source_row) {if ($ source_row [$ match] == $ Include_to_row [$ match]) {foreach ($ source_row $ source_column_key => $ Source_column_value) {$ include_to_row [$ source_column_key] = $ source_column_value; }}} Return $ include_to_row; } ($ MA = 0; $ MA & lt; count ($ MainArray); $ m ++) $ New Merrenarere [$ MA] = Included formarm ($ include $ $ $, $ type $ id, "type_id"); ( 1 [name] => test1 [helptxt]  

Result:

  array ([0] => = > Help text for item ID 1. [Type_id] => 1 [typeetile] => number [typed] => description text type_ id 1)  
  [1] => ; Array ([Item_id] = & gt; 2 [Name] = & gt; Test2 [helptxt] => Help text for item-id2. [Type_id] => 2 [typetitle] => Price [Typedesc] = & gt; description text type_ id 2)  

)


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -