Hello,

there is an error in your example:
if($index) wouldn't allow to set the value of index "0". You should use if (is_null($index)) instead.