What is the difference between index and key in PHP arrays?

In PHP arrays, the terms "index" and "key" are often used interchangeably to refer to the position of an element within an array. However, there is a subtle difference between the two. An index is a numeric value that represents the position of an element in a numerically indexed array, while a key is a string value that represents the name of an element in an associative array. It is important to use the correct terminology when working with arrays in PHP to avoid confusion and ensure clarity in your code.

// Example of using index in a numerically indexed array
$numbers = [10, 20, 30];
echo $numbers[1]; // Output: 20

// Example of using key in an associative array
$colors = ['red' => 'apple', 'yellow' => 'banana', 'orange' => 'orange'];
echo $colors['yellow']; // Output: banana