Intelligent Design Sort implementation for PHP