bashabi Posted March 28, 2023 Share Posted March 28, 2023 The first array is a result of database model query. The structure is a database model structure. $array1 = Array ( [0] => Array ( [name] => ID [table] => DatabaseModelTable ) [1] => Array ( [name] => GuestListID [table] => DatabaseModelTable ) [2] => Array ( [name] => Name [table] => DatabaseModelTable ) [3] => Array ( [name] => UpdatedAt [table] => DatabaseModelTable ) [4] => Array ( [name] => UpdaterPeopleID [table] => DatabaseModelTable ) [5] => Array ( [name] => ConcRV [table] => DatabaseModelTable ) ) The second array is a result of another select query. The structure of this array is like following $array2 = Array ( [0] => Array ( [ID] => 1 [NumberOfTickets] => 21 ) [1] => Array ( [ID] => 2 [NumberOfTickets] => 12 ) ) The relation between two arrays s ID . I want to merge these two array and make it one single array . The resulting array actually will add an extra column in the first array and look like the following $result = Array ( [0] => Array ( [name] => ID [table] => DatabaseModelTable ) [1] => Array ( [name] => GuestListID [table] => DatabaseModelTable ) [2] => Array ( [name] => Name [table] => DatabaseModelTable ) [3] => Array ( [name] => UpdatedAt [table] => DatabaseModelTable ) [4] => Array ( [name] => UpdaterPeopleID [table] => DatabaseModelTable ) [5] => Array ( [name] => ConcRV [table] => DatabaseModelTable ) [6] => Array ( [name] => NumOfTickets [table] => DatabaseModelTable ) ) How can I do that. Please help me with code. I am really very bad with array and loops Quote Link to comment https://forums.phpfreaks.com/topic/316060-i-need-help-merging-2-different-multidimensional-associative-arrays/ Share on other sites More sharing options...
requinix Posted March 28, 2023 Share Posted March 28, 2023 Obvious question: why isn't the first query returning what you want, instead of you faking the data yourself? Second question: How did you, as a human being, decide what to do with $array2 to get that merged version? Because I can't see how [ID=1,NumberOfTickets=21] [ID=2,NumberOfTickets=12] translates into [name=NumOfTickets,table=DatabaseModelTable]. Quote Link to comment https://forums.phpfreaks.com/topic/316060-i-need-help-merging-2-different-multidimensional-associative-arrays/#findComment-1606904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.