DEV Community

Discussion on: Daily Challenge #306 - Largest Possible Product

Collapse
 
peter279k profile image
peter279k

Here is the simple solution in PHP:

function adjacentElementsProduct($array) {
  $max = [];
  foreach ($array as $number) {
    $next = next($array);
    if ($next === false) {
      break;
    }
    $max[] = $number * $next;
  }

  return max($max);
}
Enter fullscreen mode Exit fullscreen mode