Jump to content

Recommended Posts

Morning all

 

I have 2 multidimentional arrays, where theoretically they can continue to the nth dimension.

 

Is there a way (without using a horrible recursive function) I can iterate through both arrays and only return values where the keys are the same but the values are different?

Link to comment
https://forums.phpfreaks.com/topic/266848-more-array-hell/
Share on other sites

What you could do is loop through each of the arrays in the array and put them all together in one large new array. You will have to check if the key you add already exists in the array, if it does, you must check if it's the same value or different. If it's different, then you can store that somewhere else (but these are the values you want to "collect", or maybe the one that already is in the "large array", so make sure you store them all and where you got them from), if it is not different you don't need to add it to the "large array" again! ;)

 

Sorry if there is some kind of logical error, it made sense in my tired head!

Link to comment
https://forums.phpfreaks.com/topic/266848-more-array-hell/#findComment-1368054
Share on other sites

Short answer: No.

 

If you have an unknown number of dimensions in your arrays, you will need to use a recursive function to traverse them all. That's just the reality of it.

There isn't an unknown number of dimensions in his array. It's a 2 dimensional array, at least he states so... :P Meaning it's an array that contains arrays! ;) If what he says is correct, I think what I said/thought will work.

Link to comment
https://forums.phpfreaks.com/topic/266848-more-array-hell/#findComment-1368110
Share on other sites

Would I be wrong to say that the idea behind my post would be a good idea? I mean loop through all the data, making a "map" of everything you're going through, separating and collecting the things you want to collect? :)

 

I think it should be quite easy to write if it's a recursive method inside a class, because then the recursive class can store the map and the collection in a private property in the class. :o

Link to comment
https://forums.phpfreaks.com/topic/266848-more-array-hell/#findComment-1368295
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.