Ad
  • Default User Avatar

    This is because substr prints the number of characters after the starting index. Had you started from 0, you would just need to subtract 1 to exclude the last element.
    But since you have started from 1, it has shifted the range by 1, which means the last character is included again. So you need to subtract 2.