![]() |
Array merge on similar key => value
I have three arrays I'm working with based on queries pulled from a database. All of them have one key => value pair in common, and I'm looking for the most elegant way to merge these arrays.
array_merge() of course won't work, and I'm curious if there's a better solution than iterating through and merging it 'by hand' so to speak within a loop. For example, the arrays all follow this paradigm; Code:
ArrayCode:
Array |
you could use a combination of intersect, diff, and merge like this:
PHP Code:
|
Thanks Tony, I wound up just looping through it directly; The above method won't work on the array for me as a whole due to the fact that I'd still have to loop through and merge each key seperately, and trying to run the intersect and diff on the top level of the array doesn't work.
Were I to loop through I'm sure something along the lines of, PHP Code:
I'm a huge fan of array_s(p)?lice, array_search, et al, but there's some I've never had the chance to use yet and it was nice to play with them a little. :) |
| All times are GMT. The time now is 11:07 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0