What are some best practices for handling multidimensional arrays in PHP to avoid incorrect results?

When working with multidimensional arrays in PHP, it's important to pay attention to the keys used to access values. Using numeric keys can lead to unexpected results, especially when looping through arrays. To avoid incorrect results, it's best to use associative keys or properly iterate through the array structure.

// Example of iterating through a multidimensional array using foreach loop
$multiArray = [
    'first' => [
        'name' => 'John',
        'age' => 30
    ],
    'second' => [
        'name' => 'Jane',
        'age' => 25
    ]
];

foreach ($multiArray as $key => $innerArray) {
    foreach ($innerArray as $innerKey => $value) {
        echo "$key - $innerKey: $value\n";
    }
}