In PHP can I escape the string ‘Function’ so that it is not recognized as a function?

Solution:1

Yes, you can! The way you were using Function was wrong (as a bare word without a dollar sign in front it is assumed to either be a reserved word or a constant). Put a dollar sign in front of it so it gets interpreted as a variable.

if (isset($Function)) {
  if ($Function == 'A') {
    $functionID = '4';
  } else if ($Function == 'B'){
    $functionID = '11';
  }  
} else {
  $functionID = 0;
}

Please note that Function is not a string:

  • A string would have been "Function".
  • Function is a reserved word
  • Some_Function is a constant (as it’s not reserved)
  • $Function is a variable
  • Some_Function() would have been a function call.

Solution:2

In your code, you are not accessing array data. Instead, you are trying to access a single variable named $Function.

Suppose the array is stored in a variable named $arr. Then in order to check value of its ‘Function’ field (element with index ‘Function’) you should write:

if ($arr['Function'] == 'A') {
    // ...your action code here
}