Police are piecing together the timeline of events before and after the mass shooting at a high school in Florida, saying the suspect stopped at both Subway and McDonald's before being arrested.

Broward County Sheriff Scott Israel told reporters that the suspected shooter, 19-year-old Nikolas Cruz, arrived at Marjory Douglas High School via Uber at 2:19pm local time (8:18pm BST) on Wednesday. The Uber driver is not implicated at this time, the sheriff said.

From there, the former Marjory Douglas student entered the building, carrying a legally purchased AR-15 rifle and multiple magazines. He began spraying bullets into nearby classrooms, occasionally returning to certain rooms to hit them again.

In total, police say Mr Cruz killed 17 students and staff and injured 14.

Less than 40 minutes after he began his rampage, Mr Israel said, Mr Cruz dropped his rifle and backpack and fled the school on foot, blending in with the students running for their lives from the building.

The suspect entered a Subway inside a Walmart nearby and purchased a drink, Mr Israel said. He then went to a McDonalds and sat for several minutes. He was eventually detained in a residential area two miles from the school at 3:41pm (9:41pm BST).

Florida shooting – in pictures Show all 10 1 /10 Florida shooting – in pictures Florida shooting – in pictures Police arrest a suspect in connection with the shooting at the Marjory Stoneman Douglas High School in Parkland, Florida Reuters Florida shooting – in pictures Parents wait for news after reports of a shooting at Marjory Stoneman Douglas High School in Parkland, Florida AP Florida shooting – in pictures Anxious family members wait for news of students AP Photo/Wilfredo Lee Florida shooting – in pictures Students being evacuated from the school AP Florida shooting – in pictures Students being evacuated from the school Getty Florida shooting – in pictures People gather waiting for word from students AP Florida shooting – in pictures Parents waiting for news on their children AP Florida shooting – in pictures People gather at a hotel where students were taken after the shooting Getty Florida shooting – in pictures Florida Governor Rick Scott speaks to the media as he visits Marjory Stoneman Douglas High School following the shooting AFP/Getty Florida shooting – in pictures Dr. Igor Nichiporenko, Medical Director Trauma, left, and Dr. Evan Boyer, Medical Director, Emergency Services, speak about treating victims and the suspect at a press conference outside Broward Health North hospital AP

Mr Cruz’s attorney defended him after his first court appearance on Thursday, telling reporters her client was said and remorseful, and was just a "broken human being”. The judge order Mr Cruz held without bond.

Mr Israel said the sheriff’s office had interviewed more than 2,000 people in connection with the shooting, and their investigation was ongoing. Law enforcement officials are reviewing Mr Cruz’s social media accounts, along with surveillance video of the incident, he said.

Florida shooting suspect Nikolas Cruz appears in court the day after mass shooting

FBI special agent in charge Rob Lasky briefed reporters on a YouTube comment apparently left by Mr Cruz in 2015. The comment, left by someone with the username “nikolas cruz” said simply: “Im going to be a professional school shooter”.

Mr Lasky said the comment had been reported to YouTube at the time, and quickly removed. The person who reported the comment lived in Mississippi, he added, and had no connection to Mr Cruz or to Florida.

“Moving forward, we will continue to gather all information about the subject as we try to identify his motives, his associates, and his actions leading up to yesterday’s events,” Mr Lasky said.

He added: “We are looking into his social media posts, his movements, his conversations leading up to the shooting, as well as any other indicators that may be out there.”