8 Replies Latest reply on Jul 3, 2008 1:18 PM by Scooby_Doobie_Doo

# Compare Array Value to another Array Value?

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?
• ###### 1. Re: Compare Array Value to another Array Value?
Use the fact that the keys in a struct avoid duplication. Here is an example.

• ###### 2. Re: Compare Array Value to another Array Value?
Where do these arrays come from?
• ###### 3. Re: Compare Array Value to another Array Value?
I create them in different areas of the web site.
• ###### 4. Re: Compare Array Value to another Array Value?
> 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)

--
• ###### 5. Re: Compare Array Value to another Array Value?
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.

• ###### 6. Re: Compare Array Value to another Array Value?
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.
• ###### 7. Re: Compare Array Value to another Array Value?
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.

• ###### 8. Re: Compare Array Value to another Array Value?
Thanks Guys, I was able to use the structure and then compare it to my other array, worked like a CHARM! Thanks again.