Are there best practices for optimizing PHP code when working with complex data structures like multidimensional arrays?

When working with complex data structures like multidimensional arrays in PHP, it's important to optimize your code for performance. One best practice is to minimize the number of nested loops and use built-in array functions whenever possible. Additionally, consider using associative arrays instead of numerical indexes for better readability and maintainability.

// Example of optimizing PHP code with multidimensional arrays

// Bad practice: nested loops
foreach ($array as $key1 => $value1) {
    foreach ($value1 as $key2 => $value2) {
        // Do something
    }
}

// Good practice: using array functions
foreach ($array as $subArray) {
    $filteredArray = array_filter($subArray, function($value) {
        return $value > 0;
    });
}