A PHP program made in the previous section runs normally on the server. When someone else obtains the local test, the warning "Notice: Undefined index:" Always appears, this is only a WARNING (NOTICE or WARNING) generated because of different PHP versions, rather than an ERROR ). When PHP variables are used without declaration, PHP4 runs normally, but the above warning or prompt appears in the PHP5 environment. After searching and querying, We can summarize the following three methods to solve Notice: Undefined index.
Method 1: Modify the PHP configuration file to block such warnings and prompts.
Modify the php. ini configuration file and change error_reporting to error_reporting = E_ALL &~ E_NOTICE. In this way, the program will be ignored when there are NOTICE and WARNING deficiencies. Of course, this is not suitable for new users, not only is it inconvenient to debug the program, but also is not conducive to the development of good code habits.
Method 2: Initialize each variable
Assign a null value or any value without affecting the operation. This is cumbersome for programs with many variables, but it is also a good habit to set variables in advance every time, for example:
$ Blank = ""; $ price = "15": $ car = "Truck": method 3: Add "@" before each variable
It is easy and practical. It is usually used in combination with the second and third types.