What are common beginner mistakes when working with arrays in PHP?

One common beginner mistake when working with arrays in PHP is not properly initializing an array before trying to access or modify its elements. This can lead to errors or unexpected behavior. To solve this issue, always initialize an array before using it.

// Incorrect way - not initializing the array before using it
$myArray[] = 'apple';
print_r($myArray); // Notice that $myArray is not defined

// Correct way - initializing the array before using it
$myArray = array();
$myArray[] = 'apple';
print_r($myArray); // Outputs: Array ( [0] => apple )