@ 2017-11-15T10:22:52Z <?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]["OPTIONS"][$line[0]] = explode(" ", $line, 2)[1];
}Else{
$res[$q]["ANSWER"] = explode(" ", $line, 2)[1];
}
}
}
Var_dump($res);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.25 , 7.1.0 - 7.1.20 , 7.2.5 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.19 , 8.3.0 - 8.3.4 , 8.3.6 - 8.3.7 array(3) {
[1]=>
array(3) {
["QUESTION"]=>
string(68) "Abuja, the Federal Capital Territory has -- -- -- -- -- area Council"
["OPTIONS"]=>
array(4) {
["A"]=>
string(1) "4"
["B"]=>
string(1) "6"
["C"]=>
string(1) "7"
["D"]=>
string(1) "2"
}
["ANSWER"]=>
string(1) "B"
}
[2]=>
array(3) {
["QUESTION"]=>
string(84) "The Federal Capital Territory is associated with-- -- -- -- -- -- -- vegetation belt"
["OPTIONS"]=>
array(4) {
["A"]=>
string(13) "Sahel savanna"
["B"]=>
string(10) "Rainforest"
["C"]=>
string(14) "Guinea savanna"
["D"]=>
string(13) "Sudan savanna"
}
["ANSWER"]=>
string(1) "C"
}
[3]=>
array(3) {
["QUESTION"]=>
string(84) "The most significant factor responsible for the ever increasing population of FCT is"
["OPTIONS"]=>
array(4) {
["A"]=>
string(15) "High birth rate"
["B"]=>
string(11) "Immigration"
["C"]=>
string(10) "Death rate"
["D"]=>
string(6) "CENSUS"
}
["ANSWER"]=>
string(1) "B"
}
}
Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array(3) {
[1]=>
array(3) {
["QUESTION"]=>
string(68) "Abuja, the Federal Capital Territory has -- -- -- -- -- area Council"
["OPTIONS"]=>
array(4) {
["A"]=>
string(1) "4"
["B"]=>
string(1) "6"
["C"]=>
string(1) "7"
["D"]=>
string(1) "2"
}
["ANSWER"]=>
string(1) "B"
}
[2]=>
array(3) {
["QUESTION"]=>
string(84) "The Federal Capital Territory is associated with-- -- -- -- -- -- -- vegetation belt"
["OPTIONS"]=>
array(4) {
["A"]=>
string(13) "Sahel savanna"
["B"]=>
string(10) "Rainforest"
["C"]=>
string(14) "Guinea savanna"
["D"]=>
string(13) "Sudan savanna"
}
["ANSWER"]=>
string(1) "C"
}
[3]=>
array(3) {
["QUESTION"]=>
string(84) "The most significant factor responsible for the ever increasing population of FCT is"
["OPTIONS"]=>
array(4) {
["A"]=>
string(15) "High birth rate"
["B"]=>
string(11) "Immigration"
["C"]=>
string(10) "Death rate"
["D"]=>
string(6) "CENSUS"
}
["ANSWER"]=>
string(1) "B"
}
}
preferences:dark mode live preview
154.78 ms | 404 KiB | 183 Q