Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    797
    Thanks
    4
    Thanked 1 Time in 1 Post

    How to resolve undefined offset notices

    How do you resolve these undefined offset notices?

    The problem is where you make a mathematical adjustment x+1 or x-1, that's where it shows these notices.

    Notice: Undefined offset: -1 in C:\xampp\htdocs\biblewheel-php\bible_with_concordance\index.php on line 486

    Notice: Undefined offset: 332 in C:\xampp\htdocs\biblewheel-php\bible_with_concordance\index.php on line 515

    Notice: Undefined offset: -1 in C:\xampp\htdocs\biblewheel-php\bible_with_concordance\index.php on line 558

    Notice: Undefined offset: 234 in C:\xampp\htdocs\biblewheel-php\bible_with_concordance\index.php on line 585
    PHP Code:
        $previous = ($i-1);
        
    $next = ($i+1);
        if((
    $verse[$i])!==$verse[$previous]){ 
    and
    PHP Code:
    if($verse2[$i]!==$verse2[$next]){ 
    My youtube channel:
    https://www.youtube.com/channel/UCme...H42czlwGaBX8JA

    Compare bible texts (and other tools):
    The Biblewheel

  2. #2
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    5,512
    Thanks
    22
    Thanked 567 Times in 560 Posts
    How do you resolve these undefined offset notices?
    you test, whether the index exists (PHP: isset - Manual) before you use it.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  3. #3
    Regular Coder Vege's Avatar
    Join Date
    Jan 2008
    Posts
    839
    Thanks
    21
    Thanked 114 Times in 113 Posts
    Those notices seems to be errors in your code. Code might work even with warnings but you should fix those.
    You are basically using indexes of the array that don't exist. Make sure you add constraints (if statements usually) to remove those errors.
    Don't allow your code to come into situation where you can use an array item that don't exist.
    You can check the flow with isset or just set it to something with PHP7
    $var = $notset??1;

  4. #4
    Regular Coder
    Join Date
    Mar 2005
    Posts
    797
    Thanks
    4
    Thanked 1 Time in 1 Post
    Concerning isset:
    Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
    But $i is from the forloop.
    My youtube channel:
    https://www.youtube.com/channel/UCme...H42czlwGaBX8JA

    Compare bible texts (and other tools):
    The Biblewheel

  5. #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    4,080
    Thanks
    3
    Thanked 506 Times in 494 Posts
    If you are looping over array(s) of data, you need to use a loop construct that loops over just the elements of the array(s) that exist, such as a foreach(){} loop, rather than to manipulate your own array index values.

    What exactly are you trying to accomplish and what is your data structure, since your snippets of code don't convey enough information, and it may be that the method you are trying to use doesn't even fit for what you are trying to accomplish.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

  6. #6
    Regular Coder
    Join Date
    Mar 2005
    Posts
    797
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by CFMaBiSmAd View Post
    If you are looping over array(s) of data, you need to use a loop construct that loops over just the elements of the array(s) that exist, such as a foreach(){} loop, rather than to manipulate your own array index values.

    What exactly are you trying to accomplish and what is your data structure, since your snippets of code don't convey enough information, and it may be that the method you are trying to use doesn't even fit for what you are trying to accomplish.
    I find the foreach loop more complicated to understand and set up than the for loop
    My youtube channel:
    https://www.youtube.com/channel/UCme...H42czlwGaBX8JA

    Compare bible texts (and other tools):
    The Biblewheel


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •