How can the correct syntax for appending errors to an array in PHP be ensured?

When appending errors to an array in PHP, it is important to ensure that the correct syntax is used to avoid any errors. To ensure the correct syntax, you should use square brackets [] to append errors to the array. This will ensure that each error is added as a new element in the array.

$errors = []; // Initialize an empty array to store errors

// Append errors to the array using square brackets []
$errors[] = "Error message 1";
$errors[] = "Error message 2";
$errors[] = "Error message 3";

// Print out the errors
print_r($errors);