How can you properly access values in an array using square brackets in PHP?

To properly access values in an array using square brackets in PHP, you need to specify the index of the element you want to access within the square brackets following the array variable. The index can be a numerical value for indexed arrays or a string key for associative arrays. Remember that array indices start at 0 for the first element. Make sure to use the correct syntax to avoid errors when accessing array values.

// Example of accessing values in an array using square brackets
$array = [10, 20, 30, 40];
echo $array[0]; // Output: 10

$assocArray = ['key1' => 'value1', 'key2' => 'value2'];
echo $assocArray['key1']; // Output: value1