Home > Article > Backend Development > Three solutions to Notice: Undefined index appearing in PHP_PHP Tutorial
A PHP program I made in the previous paragraph runs normally on the server, but when someone else takes it to the local computer for testing, a warning like "Notice: Undefined index:" always appears. This is just a warning (NOTICE or WARNING) caused by different PHP versions. ), not an error (ERROR). When variables in PHP are used without declaration, PHP4 runs normally, but in the PHP5 environment, the above warnings or prompts will appear. After searching and querying, we summarized the following three methods to solve Notice: Undefined index.
The first method: modify the PHP configuration file to block such warnings and prompts
Modify the php.ini configuration file and modify error_reporting to error_reporting = E_ALL & ~E_NOTICE. In this way, deficiencies of NOTICE and WARNING in the program will be ignored. Of course, this is not suitable for novices. Not only is it inconvenient to debug the program, but it is also not conducive to developing good coding habits.
Second method: Initialize each variable
Just assign a null value or any value and it will not affect the operation. This is cumbersome for programs with many variables, but it is also a good habit to set the variables in advance every time, for example:
$blank = "";$price = "15":$car = "Truck":The third method: add "@" in front of each variable
It is very easy and practical. Generally, the second and third methods are used together.