in reply to Filtering array based off of two values against second array
for each entry where [ 1 ] or [ 3 ] matches any of the [ 1 ]'s in Array 2
Sorry, but even after re-reading your post twice, this part of the explanation doesn't make sense to me, what is this "[ 1 ] or [ 3 ]" - why should sub_id only match indicies 1 and 3, and/or why does your sample output include all of Array_1 plus the entries sub_id1_data and sub_id2_data (note the emphasis)? And what does "any of the [ 1 ]'s" mean, I see only one entry at each index 1? If you could explain more - best of course with example input, runnable code, and expected output for that input - we could be of more assistance.
For now, I can only guess that you might want to build a regex out of Array_2 and grep Array_1 with that regex, and for the second part of your question pushing the results back onto Array_1.
provide a functional snippet....so I'm not going to. I think the question is easy enough to pose, so I'm hoping I don't get too many "follow all the rules" replies.
The "rules"* are not there just for the sake of being rules or because we like being picky (although that often comes with the territory in programming ;-) ), but because experience has shown it's the most straightforward way to see the problem and provide help, and sorry but your post is another example of that - see my questions above, for example, if the confusion results from typos in the indicies, runnable code would have caught that. So: I know what I mean. Why don't you? How do I post a question effectively? and Short, Self-Contained, Correct Example.
* Update: Don't think of them as "rules", but as advice to help post good questions. Good questions are not good because they followed all the rules, but because they efficiently provide all the information needed to get good answers. It may be a cliche but in this case it's extremely fitting: Help us help you. (We're all here voluntarily.) Plus, the process of crafting a good question itself will often bring you closer to the answer, since for example cutting your code down to an SSCCE is the same as one would do when debugging anyway.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Filtering array based off of two values against second array
by holli (Abbot) on Oct 27, 2017 at 03:35 UTC |