Created
February 11, 2016 08:16
-
-
Save ahmadshah/d3606b42a5c2060a66b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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