How do i fix "notice: undefined offset" in php?

Example:

$arr = array("apple");
echo $arr[1];
This notice is shown when you try to access an array element using an index that doesn't exist.

Solution:

if (isset($arr[1])) {
    echo $arr[1];
}

Beginner's Guide to PHP