I'm using $query, $row, etc.. variables in my code multiple time, and assigning different things to them. I wonder if it's matter or wrong coding style? Does it affect to website or server performance anyway?
Assigning different values to variables is fine. It's what variables are for, really. It only becomes a problem if you assign different meanings to the variables. For example, re-using a variable called $query
to hold something that isn't a query can be confusing and unintuitive to anybody who has to support the code (including yourself after you've forgotten about it).
As long as the variables maintain what they mean in the context of the code, you can re-assign them all you want.
It depends, and there is no single answer, you know.
In cases you mention ($query, $row) it's better to reuse variabls.
So, just make it sensible and don't make yourself a trouble out of nowhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With