Skip to content

Instantly share code, notes, and snippets.

@ahmadshah
Created February 11, 2016 08:16
Show Gist options
  • Save ahmadshah/d3606b42a5c2060a66b7 to your computer and use it in GitHub Desktop.
Save ahmadshah/d3606b42a5c2060a66b7 to your computer and use it in GitHub Desktop.
$source = ['1:8', '2:8', '1:9', '2:9', '3:1'];
$cleanArray = [];
function split_source($str) {
$exp = explode(':', $str);
return $exp;
}
foreach ($source as $s) {
list($question, $answer) = split_source($s);
if (array_key_exists($question, $cleanArray)) {
array_push($cleanArray[$question], $answer);
} else {
$cleanArray[$question] = [$answer];
}
}
print_r($cleanArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment