Get Website id from website code Magento 2.

Magento 2, You can retrieve Website id from the website code. Sometimes you need website id from the code, You have website code already exists but need website id, You can get it simply with Magento.

Use Interface:
Magento\Store\Api\WebsiteRepositoryInterface

Use method from the interface:
public function get($code);

Call from the template or any PHP class,
$code = “base”;
echo $websiteId = $this->getWebsiteId($code);

Output:
(int)1
If Website not found return null.

Above is the example of Retrieve Website Id from the website code Magento 2 and  Get Website id from the base website code.