I am of yours, in simple things do it as simply as possible.
Of course, if you are learning the ideal is to learn to do even in simple examples of the way you do when the project is complex, multidisciplinary, in a team and will require a lot of maintenance. Knowing how to make the complex helps to make the simple, as long as you do not lose sight of the simplified form. A pity that many programmers end up adopting the complex even in cases that do not need all this. So I give the teacher reason too, I just think he should have explained why, teachers are for that. It may be that he left it for you to turn around, good teachers also do it, but it doesn’t leave you lost all the time.
The answer is in the question. The separation helps each file have its own responsibility, so one takes care of the look of the page and the other takes care of the behavior it will have. This helps to test, maintain and even swap for another component if it is well done and give room for the exchange of parts.
It does not mean that HTML can not have anything PHP, can what is necessary to build the page, has to be very simple, but not to manipulate data, do real processing, take care of business rules.
Understand the whole to make your own decisions.
Not quite so, maybe the best was even you ask for it, or else post as you made the code ... even so can be answer based on own opinion, at the end of the accounts there is no way to get away from it ... the framework tries to be to the maximum, as a form of organization ... but, says there what you showed to the friend.
– novic
You should separate because it is easier to maintain code with each type of code in "your square" or in its due file. In the example you saw in the lab, maybe it didn’t make much sense to separate, because there was little code, but when you go to a corporate environment, there will be a lot more code and this separation is necessary. But I’ve never seen this separation be 100%, I use it myself
foreach
in HTML file, but I always try to use in less quantity.– Leandro Lima
Just for the fact that you question this, it’s already started right. Congratulations.
– Woss
My teacher once said to me: "Whoever asks passes for layman once, whoever does not ask will always be layman!"
– user60252
It’s good practice to mix Php and Html? and I use PHP inside an HTML or HTML inside a PHP? and a example which html mix with php and other separating.
– rray
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero