What are the best practices for dynamically searching for values in a multidimensional array in PHP without relying on hardcoded keys?

When dynamically searching for values in a multidimensional array in PHP without relying on hardcoded keys, one of the best practices is to use a recursive function that traverses the array and checks each value. This allows for flexibility in searching for any value within the array without needing to know the specific keys.

function searchValueInArray($array, $value) {
    foreach ($array as $item) {
        if (is_array($item)) {
            $result = searchValueInArray($item, $value);
            if ($result !== false) {
                return $result;
            }
        } else {
            if ($item === $value) {
                return true;
            }
        }
    }
    return false;
}

// Example usage:
$array = [
    'key1' => 'value1',
    'key2' => [
        'subkey1' => 'value2',
        'subkey2' => 'value3'
    ]
];

$searchValue = 'value3';
if (searchValueInArray($array, $searchValue)) {
    echo "Value found in array!";
} else {
    echo "Value not found in array.";
}