如何解决未定义的偏移通知?它总是显示出来

时间:2013-05-24 02:50:09

标签: php error-handling

当我使用PHP运算符比较2个数组值时,我遇到了一些问题。并注意这样的错误:Notice: Undefined offset: 1 in C:\wamp\www\始终显示在我的浏览器上。我一直在修复它。但是当我执行它时它会显示相同的结果。有人可以帮我解决吗?

$perbandingan = mysql_query("SELECT * FROM ar_produk_detail WHERE id_produk = '$_GET[id]'");
    $rows = mysql_num_rows($perbandingan);
    while($w = mysql_fetch_array($perbandingan)){
        $w_id[] = $w['id_subkategori'];
        $p_id[] = $w['id_produk_det'];
        $d_id[] = $w['id_produk'];
    }

    $data = $_POST['checkbox'];
    $sum = count($data);

for($t = 0; $t < $rows; $t++){
    if($w_id[$t] == $data[$t]){ //Notices error always reference by this line
        mysql_query("DELETE FROM ar_produk_detail WHERE id_produk_det = '$p_id[t]'");
}

1 个答案:

答案 0 :(得分:2)

您可以检查以确保条件中存在偏移:

if(isset($w_id[$t]) && isset($data[$t]) && $w_id[$t] == $data[$t])