while sometimes code is posted, its not the responsibility of the people of this forum to write your code for you... but here is how you can write pyro's code in php, its actually very simple
the code is almost line for line from the javascript
instead of Math.random() you can use [man]mt_rand/man or [man]rand/man
a basic [man]for[/man] loop works exactly the same,
variable in php are prefixed with a $
and to write html you would use either [man]echo[/man] or [man]print[/man]