3v4l.org

run code in 300+ PHP versions simultaneously
<?php // $str = file_get_contents("text.txt"); $str = "1. Abuja, the Federal Capital Territory has -- -- -- -- -- area Council A. 4 B. 6 C. 7 D. 2 ANSWER: B 2. The Federal Capital Territory is associated with-- -- -- -- -- -- -- vegetation belt A. Sahel savanna B. Rainforest C. Guinea savanna D. Sudan savanna ANSWER: C 3. The most significant factor responsible for the ever increasing population of FCT is A. High birth rate B. Immigration C. Death rate D. CENSUS ANSWER: B"; $arr = explode("\n", $str); $res=[]; Foreach($arr as $line){ If($line != ""){ If(is_numeric($line[0])){ $res[$line[0]] =["QUESTION" =>explode(" ", $line,2)[1]]; $q = $line[0]; }Else if(ctype_alpha($line[0]) && $line[1] == "."){ $res[$q][$line[0]] = explode(" ", $line, 2)[1]; }Else{ $res[$q]["ANSWER"] = explode(" ", $line, 2)[1]; } } } Var_dump($res);

preferences:
29.6 ms | 402 KiB | 5 Q