notice:undefined offset Solution, noticeundefined_php tutorial

Source: Internet
Author: User

notice:undefined Offset Solution, noticeundefined


The error message always occurs when you debug a program:

Notice: Undefined offset:1 in XXX. php
Notice: Undefined offset:2 in XXX. php

Notice: Undefined offset:3 in XXX. php

Notice: Undefined offset:4 in XXX. php

This problem often occurs in the array, the program is able to run correctly, but there is always a hint on the screen: notice:undefined offset: .... It is generally used to suppress its display, that is, change the error_repoting parameter in the php.ini file to "Eall & Notice" so that the screen will display normally.

The problem is solved, but always think about the offset: The next number (such as notice:undefined offset:4 ...) is what it means. Also, the syntax in the sentence is clearly correct, and why the warning appears. Calmly pondered several times and tried every possible Finally found the answer. Offset: The next number is the array subscript of the error, generally beyond the range of values of the array, such as the definition of the array $a[] There are 10 of the number of elements, if there is $a[10] will appear error (notice:undefined offset:10 ...), Since the subscript of the array starts at 0, the subscript of this array can only be 0~9. Therefore, in the event of such problems, do not rush to suppress the display of the method (more simple can be at the front of the current file with a "error_reporting (offset: the next number); Be sure to pay attention to the array subscript you use, think about it, the problem will soon be solved! It is also possible to try to read the contents of the unset array, and the PHP manual contains:

Just to confirm, USING the UNSET CAN DESTROY an entire ARRAY. I couldn ' t find reference to this anywhere so I decided to the write this.

The difference between using unset and using $myarray =array (); To unset was that obviously the array would just be overwritten and would still exist.
$myarray =array ("Hello", "World");
echo $myarray [0]. $myarray [1];
Unset ($myarray);
$myarray =array ();
echo $myarray [0]. $myarray [1];
Echo $myarray;
?>
Output with unset is:
HelloWorld
notice:undefined offset:0 in c:webpagesdainsidermyarray.php on line 10
notice:undefined offset:1 in c:webpagesdainsidermyarray.php on line 10
Output with $myarray =array (); is:
?>
HelloWorld
notice:undefined offset:0 in c:webpagesdainsidermyarray.php on line 10
notice:undefined offset:1 in c:webpagesdainsidermyarray.php on line 10
Array

?>

This is the root cause of the problem.

http://www.bkjia.com/PHPjc/995934.html www.bkjia.com true http://www.bkjia.com/PHPjc/995934.html techarticle notice:undefined Offset Solution, noticeundefined Debug program always appear error prompt: notice:undefined offset:1 in XXX. php tice:undefined o ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.