0

I have some code that runs fine until it hits this:

if(array_key_exists($snIdx, $fields));
    $surnameField = trim($fields[$snIdx]);

or other version I tried:

if(isset($fields[$snIdx));
    $surnameField = trim($fields[$snIdx]);

The $snIdx = -1. It gives me Undefined offset error at second line ($surname = trim...). I think I don't need to paste rest of code as the exception says there is sth wrong with those functions. My PHP version is 5.4.16.

Joe
  • 2,551
  • 6
  • 38
  • 60

1 Answers1

2

Remove the semicolon from the end of the if line. Otherwise it's equivalent to:

if( something) {
    // no-op
}
$surnameField = trim($fields[$snIdx]); // undefined offset error.
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592