使用PHP比较两个数组时遇到以下错误。使用PHP尝试匹配两个数组时遇到错误
错误:
Notice: Undefined offset: 1 in /opt/lampp/htdocs/test/search.php on line 7
Notice: Undefined offset: 1 in /opt/lampp/htdocs/test/search.php on line 15
delete the valueNotice: Undefined offset: 2 in /opt/lampp/htdocs/test/search.php on line 7
Notice: Undefined offset: 2 in /opt/lampp/htdocs/test/search.php on line 15
delete the value
我解释下面我的代码。
$maindata=array(array('id'=>3),array('id'=>7),array('id'=>9));
$childata=array(array('id'=>3),array('id'=>45));
for($i=0;$i<count($maindata);$i++){
//print_r($childata);
if(count($childata) > 0){
if(in_array($childata[$i],$maindata)){
echo "get the value \n".$maindata[$i]['id'];
echo "insert the value \n".$maindata[$i]['id'];
unset($childata[$i]);
if(count($childata) > 0){
$childata=array_values($childata);
}
}else{
echo "delete the value \n".$childata[$i]['id'];
unset($childata[$i]);
if(count($childata) > 0){
$childata=array_values($childata);
}
}
}else{
echo "get the value \n".$maindata[$i]['id'];
echo "insert the value \n".$maindata[$i]['id'];
}
}
请帮我解决这个错误。
要从条件检查内容.... –
@PHPGeek:在这里,我需要检查是否'$ childata'值存在里面'$ maindata'数组,那么这两个'echo'将执行并且该特定值将被删除。一旦'$ childata'长度将为零,则第二个else部分将执行。 – subhra
然后,我认为你需要一个单维数组而不是二维数组..有没有这个数组的需要... –