title: How to search unique array key?
body: <p>I am trying to get the key of an array based on the value.</p>
  
  <pre><code>$array1=array(
  '0'=&gt;'test1',
  '1'=&gt;'test2',
  '2'=&gt;'test3',
  '3'=&gt;'test1'
  )
  
  $array2=array(
  '0'=&gt;'11',
  '1'=&gt;'22',
  '2'=&gt;'33',
  '3'=&gt;'44'
  )
  </code></pre>
  
  <p>I have </p>
  
  <p><code>$source</code> is the needle. it could be '<code>test1</code>', '<code>test2</code>' or '<code>test3</code>'</p>
  
  <pre><code>for loop to get different $source string
  
     if(in_array($source[$i], $array1)){
        $id=array_search($source[$i],$array1);
        //I want to output 11, 22 or 33 based on $source
        //However, my $array1 has duplicated value.
        //In my case, if $source is test1, the output will be 11,11 instead of 11 and 44
  
        echo $array2[$id]);
     }
  </code></pre>
  
  <p>I am not sure how to fix this. My brain is fried. Thanks for the help!</p>