Reputation: 9225
$whichwrong = "The following questions were not answered correctly: \n\n";
$whichwrong .= "Question Number: $questionNum || Your Answer: $userAnswers[$s][$q]\n";
echo $whichwrong;
Displays:
The following questions were not answered correctly: Question Number: 2 || Your Answer: b Question Number: 4 || Your Answer: c Question Number: 5 || Your Answer: a Question Number: 1 || Your Answer: b Question Number: 3 || Your Answer: b Question Number: 1 || Your Answer: b Question Number: 2 || Your Answer: a Question Number: 1 || Your Answer: b Question Number: 2 || Your Answer: b
Why is the "\n"
not working correctly?
Meanwhile this works just fine:
$totalValue .= "Correct: {$correct}\n";
$totalValue .= "Wrong: {$wrong}\n";
Upvotes: 0
Views: 285
Reputation: 7005
If you're viewing it in a browser, you need to use <br>
- you can also use the nl2br()
function. If you're in the console, try \r\n
Upvotes: 2
Reputation: 23777
Use nl2br
for inserting html-linebreaks (<br />
)
echo nl2br($whichwrong);
Normal \n
are treated by browsers like normal whitespaces.
Upvotes: 2