How can one search for a value in a multidimensional array in PHP?

Searching for a value in a multidimensional array in PHP involves iterating through each element of the array and checking if the value matches the desired one. This can be achieved by using nested loops to traverse the array and comparing each element with the target value.

function searchInMultidimensionalArray($array, $value) {
    foreach ($array as $subarray) {
        foreach ($subarray as $element) {
            if ($element == $value) {
                return true;
            }
        }
    }
    return false;
}

// Example of how to use the function
$myArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
$searchValue = 5;

if (searchInMultidimensionalArray($myArray, $searchValue)) {
    echo "Value found in the array.";
} else {
    echo "Value not found in the array.";
}