Php 比较数据库结果和多维数组

Php 比较数据库结果和多维数组,php,Php,我有数据库中的数组和数据,需要对它们进行比较 $mydays = array( 'Monday' => array('10:00','11:00','12:00','15:00','16:00','17:00','18:00'), 'Tuesday' => array('10:00','11:00','12:00','15:00','16:00','17:00','18:00'), 'Wednesday' => array('9:00','10:0

我有数据库中的数组和数据,需要对它们进行比较

$mydays = array( 
    'Monday' => array('10:00','11:00','12:00','15:00','16:00','17:00','18:00'), 
    'Tuesday' => array('10:00','11:00','12:00','15:00','16:00','17:00','18:00'), 
    'Wednesday' => array('9:00','10:00','11:00','12:00','14:00','15:00','16:00','17:00','18:00'), 
    'Thursday' => array('9:00','10:00','11:00','12:00','14:00','15:00','16:00','17:00','18:00'), 
    'Friday' => array('9:00','10:00','11:00','12:00','14:00','15:00','16:00','17:00','18:00'), 
    'Saturday' => array('9:00','10:00','11:00','12:00') 
);

$myhours = array( 
    "2017-02-27" => array("17:00"), 
    "2017-03-01" => array("16:00","17:00","18:00"), 
    "2017-03-03" => array("17:00"), 
    "2017-03-08" => array("17:00","18:00"), 
    "2017-03-10" => array("17:00","18:00") 
);
我从数据库中检索一些数据,例如:

$thisday = Monday
$thisdate = yyyy-mm-dd
$thishour = H:i

$myday = $mydays[$thisday];

foreach ($myday as $hour) { /* loop through hours for this specific day */

// I need to find out if there is a date/hour from "$myhours" that matches my data
// ie: I have database:Monday -> I loop through the hours from $mydays:Monday
// I then have : 10:00,11:00,12:00,15:00,16:00,17:00,18:00
// from there, I need to know if, in "$myhours", I have the same hour for "$thisdate"

}
我几乎阅读了这里的每一篇文章,发现并尝试使用:

function in_multiarray($elem, $array, $field)
{
$top = sizeof($array) - 1;
$bottom = 0;
while($bottom <= $top)
{
    if($array[$bottom][$field] == $elem) {
        return true;
    } else {
        if(is_array($array[$bottom][$field])) {
            if(in_multiarray_d($elem, ($array[$bottom][$field]))) {
                return true; } else { return false; }
                } else { return false; }
    $bottom++;
    }
}   
return false;
}

if( !in_multiarray("$thisdate", $myhours, "$hour") ) { echo"good"; } else { echo"not good"; }
_multiarray($elem,$array,$field)中的函数 { $top=sizeof($array)-1; $bottom=0;
而($bottom使用
in_array
函数的简单解决方案:

...
$thisday = 'Monday'; 
$thisdate = "2017-02-27"; 
$thishour = '11:00';

// check if we have a valid weekday name and date/time value
if (isset($mydays[$thisday]) && isset($myhours[$thisdate]) 
    && in_array($thishour, $mydays[$thisday])) {
    echo 'good';
} else {
    echo "not good";
}

也许我误解了这个问题(如果是,请澄清),但对我来说,这段代码起到了关键作用:是否应该输入
$thisday='Monday';$thisdate=“2017-02-27”;$thishhour='11:00'
返回
true
?@RomanPerekhrest:yes@Bogdan当前位置我将测试这个并让您know@user3801953,好的,我已经使用了我之前评论中的输入,正如您所说,它应该返回
true
/
good