I was talking to a friend of mine who is a back-end webdev for a while now about what code is better. He said his code was better because it was "art" and i would understand in 5 years. But i don't get why his 30 lines of code is better than my 4.
What we did was that a user could input a number and the output would be something like this if the input was 7: 1 x 7 = 7 2 x 7 = 14 3 x 7 = 21 etc...
His code:
function createTablesFromNumber($x, $amount) { $output = [];
For this particular case, what he did was a bit of an overkill. I get what he is trying to say though. For future use his code is better because his function outputTablesInHTML can be used by other functions. In this particular case that's not going to happen but in real world development that happens a lot.
Its kind of hard to explain but in the long run his code will be easier to modify/build on top of by another developer.
Php is the language that I currently use more, but I'm not exactly a an expert, so what I about to say is a guess.
The code that he wrote is a result of an habit of dividing the code in blocks (functions) for the sake of reusing them in other parts of the program. I believe this part of the concept in programming called dry (don't repeat yourself) and helps reduce the number of lines of code and improves readability. I do this a lot in where usually a piece of code with more than 5 lines used at least 2 times i create function for that block.
Another thing is where he uses echo "{$i2} x {$x} = {num}"; instead of echo $i . "x" . $getal . "=" . $i*$getal; which I believe is called interpolation, is used to improve readability.
I agree with @TheCount, in this particular case is the code that he made is completely overkill. I believe you should use these concepts but not every time, in another words, find a balance.