Are there any best practices for updating and adding items to an array in PHP?

When updating or adding items to an array in PHP, it is important to use the correct syntax to ensure that the array is modified correctly. To update an existing item, you can simply assign a new value to the specific key in the array. To add a new item, you can use the array_push() function or directly assign a value to a new key in the array.

// Update an existing item in the array
$array = ['apple', 'banana', 'cherry'];
$array[1] = 'orange';

// Add a new item to the array
$array = ['apple', 'banana', 'cherry'];
array_push($array, 'orange');