Meaningful Names
Names should reveal intent. A variable called $d tells you nothing. A variable called $elapsedDays tells you everything.
Functions Should Do One Thing
The single responsibility principle applies to functions too. If you cannot describe your function in one sentence, it probably does too much.