PHP Drug Half Life Calculator

For a while now I have been wanting to build a script that will let me enter in a daily dosage amount of a drug and enter that drugs half-life time and then spit out how much of the drug remains in my system in a nice daily chart. This is really useful if you are detoxing off a drug and would like to get a good estimate on how long it will take to get it all out of your system.

First I created a simple calculator function which does the daily calculations

or you could simplify this to be

Next I made a function that I can simply pass an Array with a key => value for each day and have the dosage of the drug taken on that day. The result is a new Array returned that will have the Day, the dosage took on that day, and the remaining amount of the drug still in your system at that day.

Drug Half Life Calculator Example

Result

Final Remarks

You must remember that a Drugs half-life is different for every person and the number of hours in a half-life should just be used as an estimation and not 100% fact as every person will disregard the drug at a different rate. You can generally find a drugs half-life on Wikipedia. This calculator was just made for my personal use but you are free to do with it as you please. There is a lot of potential to improve this so if you do, let me know in the comments below!