Below is a binary tree algorithm written in PHP.