Search code examples
phpnotice

notice php - alternative or remove?


i am using this code to check if the variables $n0, $n1, $n2 are not defined.

But i get a notice each time that was not defined. My code is a bad practice? there is any alternative? or just remove the notices and the code is fine?

            if (!isset ($n0) && $n0 != $form['name0']){
                echo ("n0");
            }

            if (!isset ($n1) && $n1 != $form['name1']) {
                echo ("n1");
            }

            if (!isset ($n2) && $n2 != $form['name2']) {
                echo ("n2");
            }

thanks


Solution

  • You should actually be replacing those &&'s with ||'s. If the $n's aren't set then they surely won't equal the $form values..

    This will prevent the notices and do what you're intending