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