What is the difference between accessing values in an array and accessing values in an object in PHP?

When accessing values in an array in PHP, you use square brackets with the index of the value you want to retrieve. On the other hand, when accessing values in an object, you use the arrow operator (->) followed by the property name. Arrays are indexed by numerical keys, while objects are indexed by property names.

// Accessing values in an array
$array = ['key' => 'value'];
echo $array['key']; // Output: value

// Accessing values in an object
$obj = (object)['key' => 'value'];
echo $obj->key; // Output: value