1

I have a commments.txt file that has a name, email and a comment on each line. I am able to print the comments in this format so far but when I sort the file and then try to print it, it only prints 111 and I'm not sure why. sort.php:

$file = file("comments.txt");
$sortedAZ = sort($file);
print_r($sortedAZ);

comments.txt file:

Sally Doe sally@doe.com This is a comment
Charlie Lee charlie@lee.com This is another comment
Bob Smith bob@smith.com Hello world

So far I only have it printing like this:

Name: Sally Doe 
Comment: This is a comment
Name: Charlie Lee
Comment: This is another comment
Name: Bob Smith 
Comment: Hello world

I'm trying to sort the file in alphabetic order by the first name so that it would print out something like:

Name: Bob Smith 
Comment: Hello world
Name: Charlie Lee
Comment: This is another comment
Name: Sally Doe 
Comment: This is a comment
  • What do you mean it prints 111? You said you could get it printing in the correct format, but wrong order. – Mitya May 04 '20 at 18:05
  • If I have it unsorted, it prints fine. I used a loop to slice each element to how I want it displayed. The moment I try to print $sortedAZ, like the code above, it simply just displays the number 1. – soondubu247 May 04 '20 at 18:35

0 Answers0