title: How do I compare every element in a multidimensional array?
body: <p>I would appreciate any help with this. </p>
  
  <p>This has been edited to more clearly describe how the array should be evaluated. </p>
  
  <p>I am trying to figure out how I can compare all elements of a multidimensional array to determine if the elements comprise a true set.  </p>
  
  <p>Criteria  </p>
  
  <ol>
  <li>I won't know how big the array is going to be ahead of time (could be 2, could be 1000).  </li>
  <li>Each array element has two characteristics (color and type) that need to be compared.  </li>
  <li>If any charactistic value is shared by any two elements then all elements must share that characteristic value.  </li>
  <li>The values for 'color' &amp; 'type' can be compared as straight text, they will match or not, no variation will be possible. I.e. Green != Greene.  </li>
  <li>The function only needs to return true or false based on whether is it a true set or not. </li>
  <li>Any assistance can be given in JavaScript, PHP, or C. I can extrapolate. </li>
  </ol>
  
  <p>Array Example</p>
  
  <pre><code>var obj = {  
      'Element001' : {  
          'ID' : 'value',  
          'Color' : 'value',  
          'Type' : 'value'  
      },  
      'Element002' : {  
           'ID' : 'value',  
           'Color' : 'value',  
           'Type' : 'value'  
      }  
      ...  
  };  
  </code></pre>
  
  <p>Examples of how different arrays would evaluate.  </p>
  
  <p>The following array should evaluate to "TRUE" because all elements are red and no elements share a type.  </p>
  
  <pre><code>var obj = {  
      'Element001' : {  'ID' : '1', 'Color' : 'red', 'Type' : 'b'  },  
      'Element002' : {  'ID' : '2', 'Color' : 'red',  'Type' : 'a'  }  
      'Element003' : {  'ID' : '21', 'Color' : 'red', 'Type' : 'c'  }  
  };  
  </code></pre>
  
  <p>The following array should evaluate to "TRUE" because all elements are of type "b" and no elements share a color.  </p>
  
  <pre><code>var obj = {  
      'Element001' : {  'ID' : '1', 'Color' : 'red', 'Type' : 'b'  },  
      'Element002' : {  'ID' : '2', 'Color' : 'blue', 'Type' : 'b'  }  
      'Element003' : {  'ID' : '21', 'Color' : 'green', 'Type' : 'b'  }  
  };  
  </code></pre>
  
  <p>The following array should evaluate to "TRUE" because all elements are "blue" and all elements are of type "c".  </p>
  
  <pre><code>var obj = {  
      'Element001' : {  'ID' : '1', 'Color' : 'blue',  'Type' : 'c'  },  
      'Element002' : {  'ID' : '2', 'Color' : 'blue',  'Type' : 'c'  }  
      'Element003' : {  'ID' : '21', 'Color' : 'blue',  'Type' : 'c'  }  
  };  
  </code></pre>
  
  <p>The following array should evaluate to "FALSE" because two elements share a color "red". Per rule: If any two elements share a characteristic they must all share it. Thus all elements would have to be red. Also in this example no elements share a type.  But even if they were all of type "a" it would still evaluate to "FALSE", because of the color attribute.  </p>
  
  <pre><code>var obj = {  
      'Element001' : {  'ID' : '1', 'Color' : 'red', 'Type' : 'b'  },  
      'Element002' : {  'ID' : '2', 'Color' : 'red', 'Type' : 'a'  },  
      'Element003' : {  'ID' : '21', 'Color' : 'blue', 'Type' : 'c'  }  
  };
  </code></pre>
  
  <p>Also another that would evaluate to "FALSE" is a set where no characteristic is shared.<br>
  Such as one like this...  </p>
  
  <pre><code>var obj = {  
      'Element001' : {  'ID' : '1', 'Color' : 'red', 'Type' : 'b'  },  
      'Element002' : {  'ID' : '2', 'Color' : 'green', 'Type' : 'a'  },  
      'Element003' : {  'ID' : '21', 'Color' : 'blue', 'Type' : 'c'  }  
  };
  </code></pre>