You can find the least common multiple (LCM) of a list of numbers by using a function that computes the LCM of two numbers and applies it to the list of numbers. Here's an implementation in PHP:
main.php634 chars34 lines
The lcm_list
function takes an array of numbers and iteratively computes their LCM. It uses the lcm
function, which computes the LCM of two numbers, and the gcd
function, which computes the GCD of two numbers (needed to compute the LCM).
gistlibby LogSnag