Save the code to a file on your web server.
phpinfo();
?>
And run the script via your browser.
It will show you all the settings you've got.
Or at the command line, type ...
php -m
or
php --ri imap
The first will list all modules you've got and the second will list the settings/version/state for imap (if it is loaded).
If you get ...
Extension 'imap' not present.
then you've not got it loaded.