我在比较这些数组时遇到问题。
简而言之,我想检查
$tid_and_date_arr
是否存在于$curr_vals
内。 (看一下。显然是这样。)
我的逻辑是有缺陷的,但是,在循环过程中第二次,
$tid_and_date_arr != $value[1]
所以该值不会被跳过。
我错过了什么? 循环中又循环?
$curr_vals = array(
array('tid' => 22, 'date' => 1497250800),
array('tid' => 22, 'date' => 1497337200)
);
$tid_and_date_arr = array('tid' => 22, 'date' => 1497250800);
foreach ($curr_vals as $value) {
if ($tid_and_date_arr == $value) {
// skip these values as we've already saved them
continue;
} else {
// save these values as they are new
}
}
array_search
?
$curr_vals = array(array('tid' => 22, 'date' => 1497250800), array('tid' => 22, 'date' => 1497337200));
//$tid_and_date_arr = array('tid' => 22, 'date' => 1497250800); -- this will output 0
$tid_and_date_arr = array('tid' => 22, 'date' => 1497337200);
$result = array_search($tid_and_date_arr, $curr_vals);
print_r($result);
这将输出您要查找的子数组的键:
1