Identifying Tours to Edit

Let's identify tours to allow users to edit them.

Giving a unique identifier to each tour

We have successfully built a form that enables the user to add a tour to the list of tours. The next step will be to allow the user to edit the tour in case they made a typo or if they just want to change part of its data. Before we can do that, we need a way to identify the tour that we want to edit. So whenever we create a tour and add it to the $toursData array, we should also add an id property to give it a unique identifier (ID).

A unique ID could be a number that hasn’t been used before. We suggest you count the number of tours we have in $toursData and add one to it. If we use the resulting number as an ID, the first tour would have ID 1, the second 2, and so on. As long as we don’t delete elements from the array, this ID will be unique. Let’s modify create-tour.php so it will set an ID for every tour:

Get hands-on with 1200+ tech skills courses.