title: Split array based on value for a single dimentional array with key and value
body: <p>I am trying to split an array to different arrays based on values.
  This is my array</p>
  
  <pre><code>$myArray=('x'=&gt;'europe','y'=&gt;'europe','a'=&gt;'USA','b'=&gt;'USA','c'=&gt;'Canada');
  </code></pre>
  
  <p>I want to split the array based on value like below</p>
  
  <pre><code>$newList[europe]=(x,y);
  $newList[USA]=(a,b);
  $newLsit[Canada]=(c);
  </code></pre>
  
  <p>I tried the following </p>
  
  <pre><code>foreach($myArray as $key =&gt;$value){
  $myList[$value]=$key;
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>foreach($myArray as $key =&gt; $value){
  echo $key;
  if($value=='USA')$myList['USA']=$key;
  if($value=='europe')$myList['europe']=$key;
  if($value=='Canada')$myList['Canada']=$key;
  }
  </code></pre>
  
  <p>the output is the same</p>
  
  <pre><code> Array ( [europe] =&gt; y [USA] =&gt; b [Canada] =&gt; c )
  </code></pre>
  
  <p>I do not understand what the issue could be. Any help is much appriciated.</p>