What are some best practices for searching multidimensional associative arrays in PHP?

When searching multidimensional associative arrays in PHP, it is important to use recursive functions to traverse through the nested arrays and find the desired value. This approach allows for flexibility in searching through arrays of varying depths and structures.

function searchArrayValue($array, $value) {
    foreach ($array as $key => $val) {
        if (is_array($val)) {
            $result = searchArrayValue($val, $value);
            if ($result !== null) {
                return $result;
            }
        } else {
            if ($val === $value) {
                return $key;
            }
        }
    }
    return null;
}

// Example of searching a multidimensional associative array
$myArray = [
    'name' => 'John',
    'age' => 30,
    'address' => [
        'street' => '123 Main St',
        'city' => 'New York'
    ]
];

$result = searchArrayValue($myArray, 'New York');
echo $result; // Output: address.city