I know we can write PHP in .html format if we edit the .htaccess file.
ddType application/x-httpd-php .htm .html
What is the difference between editing .htaccess and writing PHP codes in .html file and writing PHP codes in .php file?
There is no difference. PHP written in .html works exactly the same as PHP written in .php files. However, you cannot write HTML to .php files.