注意:使用if()和elseif()语句在E:\server\htdocs\file.php中未定义的偏移量:1

注意:使用if()和elseif()语句在E:\server\htdocs\file.php中未定义的偏移量:1,php,if-statement,Php,If Statement,我正在使用以下代码: <?php include_once('/simple_html_dom.php'); $dom = file_get_html("http://www.gsmarena.com/samsung_i9300_galaxy_s_iii-4238.php"); foreach ($dom->find('tr') as $node) { if (is_a($node->children(0), 'simple_html_dom_node')) { if

我正在使用以下代码:

<?php
include_once('/simple_html_dom.php');
$dom = file_get_html("http://www.gsmarena.com/samsung_i9300_galaxy_s_iii-4238.php");
foreach ($dom->find('tr') as $node) {
if (is_a($node->children(0), 'simple_html_dom_node')) {
    if ($node->children(0)->plaintext == "Protection") {
        $plain = explode(',', $node->children(1)->plaintext);
    if($plain[0] === null){echo 'Nu are';}
     elseif($plain[0]!== null) {echo $plain[0];
     if($plain[1] === null){echo 'Nu are';}
     elseif($plain[1] !== null) {echo $plain[1];} 
     }  
    }

    }
}

?>

我只想知道是否存在$plain[x]或$plain[y]来显示是否不显示自定义文本(在我的例子中是'Nu are')。一切正常,代码运行良好,因为$plain[1]在本例中不存在,但我也收到一个错误

以下是从代码中收到的结果:

Corning Gorilla Glass 2
注意:第10行E:\server\htdocs\preluare\1.php中未定义的偏移量:1
Nu是

第一个是显示偏移量0,因为存在和第二个偏移量不存在,并显示错误和错误后是正确的自定义文本

正确的结果是
Corning Gorilla Glass 2
Nu是

而不是

$plain[1] !== null
使用


请看标题为“相关”的右侧面板-有大量相同的问题可能重复打印($explode);和回声计数($explode)
array_key_exists(1, $plain)
isset($plain[1])