How to use guard or if statement to avoid: Fatal error: Index out of range?

To clarify, 0 would be out of bounds if the array is empty.