Reputation: 13
I am trying to explode a line of texts in php. Such that, a line consists of
"[name]","[status]","[gender]","[date_of_birth]","[age]","[testing_date]","[answer_for_Test_V_nos._1_to_168]","[SAI_Raw_Score]","[RPM_Raw_Score]","[English_Raw_Score]","[Math_Test_I_Raw_Score]","[Math_Test_II_Raw_Score]","[Total_Score]"
The bold(which is 169 data all in all) is the one I'm trying to store in an array.
Here is the sample line:
"DELACRUZ JUAN H","F","M","101887","18","030105","3","0","1","2","3","3","0","2","1","0","2","1","1","3","3","3","1","2","3","3","2","1","1","2","1","2","1","3","1","0","1","3","0","2","1","0","1","3","1","1","1","1","0","2","1","1","1","2","0","3","0","3","3","1","0","2","3","3","0","2","0","2","0","0","1","2","3","3","1","2","1","3","2","2","0","3","2","2","1","1","0","0","2","3","2","0","0","2","3","3","0","1","0","3","0","1","1","3","2","0","3","1","1","0","1","2","1","0","1","3","2","0","3","0","2","2","2","2","1","1","0","3","3","3","2","3","2","1","2","3","2","1","2","0","0","1","1","2","0","0","2","3","1","2","2","3","3","1","0","0","0","0","3","2","2","1","1","3","1","1","0","2","0","2","2","1","3","2","060","055","083","015","042","0255"
Here is the code for exploding but the array here doesn't work:
list($name, $status, $gender, $bday, $age, $date, $answers[169], $SAI, $RPM, $english, $math1, $math2, $total) = explode(",", $line);
Please help, how can I explode these 169 values to each index of an array using "list() = explode()"? Or is there another way other than using list() = explode()?
Upvotes: 0
Views: 154
Reputation: 231
Just extract the values you require using array_splice.
$line = '"DELACRUZ JUAN H","F","M","101887","18","030105","3","0","1","2","3","3","0","2","1","0","2","1","1","3","3","3","1","2","3","3","2","1","1","2","1","2","1","3","1","0","1","3","0","2","1","0","1","3","1","1","1","1","0","2","1","1","1","2","0","3","0","3","3","1","0","2","3","3","0","2","0","2","0","0","1","2","3","3","1","2","1","3","2","2","0","3","2","2","1","1","0","0","2","3","2","0","0","2","3","3","0","1","0","3","0","1","1","3","2","0","3","1","1","0","1","2","1","0","1","3","2","0","3","0","2","2","2","2","1","1","0","3","3","3","2","3","2","1","2","3","2","1","2","0","0","1","1","2","0","0","2","3","1","2","2","3","3","1","0","0","0","0","3","2","2","1","1","3","1","1","0","2","0","2","2","1","3","2","060","055","083","015","042","0255"';
$splitArray = explode(",", $line);
$testAnswers = array_splice($splitArray, 6, 168); //Extract the values that you need. Leave the rest as they are.
list($name, $status, $gender, $bday, $age, $date, $SAI, $RPM, $english, $math1, $math2, $total) = $splitArray; //Put the remaining into the variables as required
var_dump($testAnswers); //All the answers
var_dump($name); //The name
Upvotes: 1