Trending algorithm in PHP?

I’m sure writing it down would be great, but it looks to be derived from an actual mathematical equation.