I have three arrays called associativeArray
keyArray
and valueArray
. associativeArray
is an array that's made up of key/value pairs, the pairs are split up and placed into keyArray
and valueArray
. What I want to do now is create a fourth array called newArray
that uses the elements in valueArray
as its keys and have the values be from their respective keyArray
. But unlike the associativeArray
that has 1:1 key-to-value, I want to have newArray
have 1:many key-to-value while not having any repeating keys. This is the code I made for it:
foreach($keyArray as $keyElement){
$valueElement = $associativeArray[$keyElement];
if (!in_array($valueElement,$newArray)){
array_push($newArray, $valueElement => array($keyElement));
}
else{
array_push($newArray[$valueElement],$keyElement);
}
}
However whenever I run it I get:
PHP Parse error: syntax error, unexpected T_DOUBLE_ARROW