Webform Message / Custom Module I'm trying to create a custom module which will display a message after my webform. I know that in order to display a message, I could use the following code:

$message = "Message here";
drupal_set_message(t($message));


But rather than having a specific message, I want to have a conditional message based on PHP if statements. E.g.,

    if($class == A) {
    print "Correct!";
}


So, my question is how can I get the results of this PHP code to display on my webform? I'm not familiar with PHP code, so I don't know if I can combine the $message code with the if statement somehow. (I've tried variations of this with no success.) 

Thanks for your help.
One of the features and APIs of the Webform module for Drupal 8 that I personally enjoy using is support for inline messages using the WebformMessage element 

The WebformMessage element supports dismissal messages and #states API.

Here is the YAML version of a Message element

message:
  '#type': webform_message 
  '#message_type': warning 
  '#message_close': true,
  '#message_storage': user,
  '#message_message': 'This message can be dismissed by a user'


Here is the PHP syntax, which can be used in your custom code.

$build['message'] = [
  '#type' =&gt; 'webform_message',
  '#message_id' =&gt; 'custom_message_id',
  '#message_type' =&gt; 'warning',
  '#message_close' =&gt; TRUE,
  '#message_storage' =&gt; WebformMessage::STORAGE_USER,
  '#message_message' =&gt; $this-&gt;t('This message can be dismissed by a user'),
];