What are some potential pitfalls when comparing indices in PHP arrays?

When comparing indices in PHP arrays, a common pitfall is using the '==' operator instead of '===' when checking for equality. The '==' operator only checks if the values are equal, while the '===' operator also checks if the types are the same. This can lead to unexpected results when comparing indices with different types, such as integer and string values. To avoid this issue, always use the '===' operator when comparing indices in PHP arrays to ensure both the values and types match.

$array1 = [1, 2, 3];
$array2 = ['1', 2, 3];

if ($array1[0] === $array2[0]) {
    echo "Indices are equal in both arrays.";
} else {
    echo "Indices are not equal in both arrays.";
}