Basic algrithms using php