What is the difference between accessing array elements and object properties in PHP?

When accessing array elements in PHP, we use square brackets [] with the index of the element we want to access. On the other hand, when accessing object properties, we use the arrow operator -> followed by the property name. It's important to remember this difference when working with arrays and objects in PHP.

// Accessing array elements
$array = ['apple', 'banana', 'cherry'];
echo $array[1]; // Output: banana

// Accessing object properties
$object = new stdClass();
$object->name = 'John';
echo $object->name; // Output: John