php error reporting Uninitialized string offset: 0 php error reporting Uninitialized string offset: 0 php php

php error reporting Uninitialized string offset: 0


For empty string, you can't use $sentence[0], that will cause the notice you got.

You can add !empty($sentence) to check if it is empty.


You are creating $sentence as a string ($sentence = "Hello World";) and then calling it as an array ($sentence[0]).That is no longer allowed.It used to work silently in the background and change the variable to an array for you with that error but as of PHP 7.1 it will fail completely.Comes out as an E_NOTICE error (should actually be upgraded to E_DEPRECATED or something as it now fails but whatever).