How can wildcards be effectively used in searching multidimensional associative arrays in PHP?

When searching multidimensional associative arrays in PHP, wildcards can be effectively used by iterating through the array and checking if the search criteria match any part of the array values. This can be done by using a recursive function that traverses the array and checks if the search criteria match any part of the array values.

function searchArray($array, $search) {
    $results = [];

    foreach ($array as $key => $value) {
        if (is_array($value)) {
            $subResults = searchArray($value, $search);
            $results = array_merge($results, $subResults);
        } else {
            if (strpos($value, $search) !== false) {
                $results[] = $value;
            }
        }
    }

    return $results;
}

// Example usage
$array = [
    'name' => 'John Doe',
    'age' => 30,
    'email' => 'john.doe@example.com',
    'address' => [
        'street' => '123 Main St',
        'city' => 'New York',
        'zip' => '10001'
    ]
];

$searchResults = searchArray($array, 'Doe');
print_r($searchResults);