There's a "nasty" bug here
Code: Select all
$idx = array_search($fields[$R], $CTSTN);
if($idx != false){ //-- valid field names
We need to use the !== operator. Please change it to:
Code: Select all
if($idx !== false){ //-- valid field names
https://stackoverflow.com/a/15934417/10132321