• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Compare Array Value to another Array Value?

Explorer ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

I have two arrays. Both 2 dimensional. The first one contains a list of names. The 2nd array contains the ID of the first array, followed with a 2nd data field. The 2nd Array can have multiple entries tied back to single ID in the first.

For example
Array 1

1 Tommy
2 Suzie
3 Billy

Array 2
1 MOVIES
2 CHEESE
1 DOGS
1 CATS


What I need to do is compare the first and second array and make sure that the 2nd has an entry for every entry in the first. So that no matter how many entries are in the 2nd array, there is at least 1 per entry, one 1 entry, one 2 and one 3 entry. I can't figure out how to do this.

I know my lenght of the first using arraylen(array)

but that doesn't help because the 2nd array can be larger and may only contain one id or two, and I need to verify it has all three. Anyone have any ideas on how to accomplish this?
TOPICS
Advanced techniques

Views

634

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

Use the fact that the keys in a struct avoid duplication. Here is an example.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 02, 2008 Jul 02, 2008

Copy link to clipboard

Copied

Where do these arrays come from?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

I create them in different areas of the web site.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

> Array 1
>
> 1 Tommy
> 2 Suzie
> 3 Billy

This sort of data really should be an array of structs (where each struct
is keyed "ID" and "name" or something). It'll *work* as an array, but the
data in the second dimension is not really array-data (there is no numeric
relationship between the "ID" and the "name" values).

A multi-dimensional array is seldom the most appropriate data type for any
common business data construct, in my view. Mathematical data - sometimes
- sure, but not business data.


> Array 2
> 1 MOVIES
> 2 CHEESE
> 1 DOGS
> 1 CATS

Ditto this one.

In fact, for what you're doing, I'd be inclined to stick them in query
objects, then you can use QoQ to perform your test:

select id
from q2
where id not in (#valueList(q1.id)#)

(or something along those lines)


--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

Dan Bracuk wrote:
Where do these arrays come from?

Does that really matter? In my example, I simply recreate Scooby Doobie Doo's second array and show how you can use a struct to list what Scooby Doobie Doo calls the IDs.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

quote:

Originally posted by: BKBK
Dan Bracuk wrote:
Where do these arrays come from?

Does that really matter? In my example, I simply recreate Scooby Doobie Doo's second array and show how you can use a struct to list what Scooby Doobie Doo calls the IDs.



Of course it does. Otherwise I wouldn't have asked.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

Dan Bracuk wrote:
Of course it does. Otherwise I wouldn't have asked.

It all amounts to zilch, of course, if you don't say.





Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 03, 2008 Jul 03, 2008

Copy link to clipboard

Copied

LATEST
Thanks Guys, I was able to use the structure and then compare it to my other array, worked like a CHARM! Thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation