title: Cakephp : Two arrays in foreach loop?
body: <p>I have 2 arrays. 1 fetching from database and other one is from view page. I am developing a online test exam website so i have to check if the answer entered by user is correct or not.Here is the 1st one. </p>
  
  <pre><code> Array
      (
          [0] =&gt; Array
              (
                  [Question] =&gt; Array
                      (
                          [id] =&gt; 51f92e34-c5a8-4de3-b264-0ff0d0483c4c
                          [aptitude_id] =&gt; 51f92441-d510-4c3d-85e3-0ff0d0483c4c
                          [paper_id] =&gt; 51f924cc-a158-441e-9119-0ff0d0483c4c
                          [qus] =&gt; What is ur name?
                          [slug] =&gt; name-find
                          [image] =&gt; 
                          [opt1] =&gt; x
                          [opt2] =&gt; y
                          [opt3] =&gt; a
                          [opt4] =&gt; b
                          [opt5] =&gt; c
                          [answer_id] =&gt; 4
                          [description] =&gt; 
                          [ansimage] =&gt; 
                      )
  
                  [Aptitude] =&gt; Array
                      (
                          [id] =&gt; 51f92441-d510-4c3d-85e3-0ff0d0483c4c
                          [name] =&gt; php
                          [slug] =&gt; php
                      )
  
                  [Paper] =&gt; Array
                      (
                          [id] =&gt; 51f924cc-a158-441e-9119-0ff0d0483c4c
                          [aptitude_id] =&gt; 51f92441-d510-4c3d-85e3-0ff0d0483c4c
                          [name] =&gt; aptitude1
                          [slug] =&gt; aptitude1
                      )
  
                  [Answer] =&gt; Array
                      (
                          [id] =&gt; 4
                          [name] =&gt; D
                      )
  
              )
  
          [1] =&gt; Array
              (
                  [Question] =&gt; Array
                      (
                          [id] =&gt; 51fe4098-c344-4790-9e46-0fb4d0483c4c
                          [aptitude_id] =&gt; 51f92441-d510-4c3d-85e3-0ff0d0483c4c
                          [paper_id] =&gt; 51f924cc-a158-441e-9119-0ff0d0483c4c
                          [qus] =&gt; Place?
                          [slug] =&gt; place
                          [image] =&gt; 
                          [opt1] =&gt; ss
                          [opt2] =&gt; sss
                          [opt3] =&gt; ss
                          [opt4] =&gt; ss
                          [opt5] =&gt; ss
                          [answer_id] =&gt; 3
                          [description] =&gt; 
                          [ansimage] =&gt; 
                      )
  
                  [Aptitude] =&gt; Array
                      (
                          [id] =&gt; 51f92441-d510-4c3d-85e3-0ff0d0483c4c
                          [name] =&gt; php
                          [slug] =&gt; php
                      )
  
                  [Paper] =&gt; Array
                      (
                          [id] =&gt; 51f924cc-a158-441e-9119-0ff0d0483c4c
                          [aptitude_id] =&gt; 51f92441-d510-4c3d-85e3-0ff0d0483c4c
                          [name] =&gt; aptitude1
                          [slug] =&gt; aptitude1
                      )
  
                  [Answer] =&gt; Array
                      (
                          [id] =&gt; 3
                          [name] =&gt; C
                      )
  
              )
  
          [2] =&gt; Array
              (
                  [Question] =&gt; Array
                      (
                          [id] =&gt; 51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
                          [aptitude_id] =&gt; 51f92441-d510-4c3d-85e3-0ff0d0483c4c
                          [paper_id] =&gt; 51f924cc-a158-441e-9119-0ff0d0483c4c
                          [qus] =&gt; hayywep?
                          [slug] =&gt; dada
                          [image] =&gt; 
                          [opt1] =&gt; a
                          [opt2] =&gt; a
                          [opt3] =&gt; a
                          [opt4] =&gt; a
                          [opt5] =&gt; a
                          [answer_id] =&gt; 3
                          [description] =&gt; 
                          [ansimage] =&gt; 
                      )
  
                  [Aptitude] =&gt; Array
                      (
                          [id] =&gt; 51f92441-d510-4c3d-85e3-0ff0d0483c4c
                          [name] =&gt; php
                          [slug] =&gt; php
                      )
  
                  [Paper] =&gt; Array
                      (
                          [id] =&gt; 51f924cc-a158-441e-9119-0ff0d0483c4c
                          [aptitude_id] =&gt; 51f92441-d510-4c3d-85e3-0ff0d0483c4c
                          [name] =&gt; aptitude1
                          [slug] =&gt; aptitude1
                      )
  
                  [Answer] =&gt; Array
                      (
                          [id] =&gt; 3
                          [name] =&gt; C
                      )
  
              )
  
      )
  
  and 
  
  
  
      Array
      (
          [51f92e34-c5a8-4de3-b264-0ff0d0483c4c] =&gt; 3
          [51fe4098-c344-4790-9e46-0fb4d0483c4c] =&gt; 3
          [51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c] =&gt; 3
      )
  </code></pre>
  
  <p>i wrote this code </p>
  
  <pre><code>foreach($res as $res1): 
  
  foreach($ans as $ans1):
  if($res1['Question']['answer_id']==$ans1)
  {
  print_r($res1['Question']['id']);
  
  }
  endforeach;
  endforeach;
  </code></pre>
  
  <p>Output: </p>
  
  <pre><code>51f92e34-c5a8-4de3-b264-0ff0d0483c4c
  51f92e34-c5a8-4de3-b264-0ff0d0483c4c
  51f92e34-c5a8-4de3-b264-0ff0d0483c4c
  51fe4098-c344-4790-9e46-0fb4d0483c4c
  51fe4098-c344-4790-9e46-0fb4d0483c4c
  51fe4098-c344-4790-9e46-0fb4d0483c4c
  51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
  51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
  51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
  </code></pre>
  
  <p>how to remove the duplication?</p>