Some basic algorithms in PHP