Some error in PHP function output I cannot understand

Have a 'function use' lesson problem. The code inside the function (when it's put outside the function; returns an array) seems correct, but the function outputs NULL. Here's what it looks. Point where I'm doing wrong, please.

function getDivisors($num)
       {
         for ($i=1; $i<=$num; $i++)
           {
             if ($num % $i == 0)
               {
                 $divisors[] = $i;
               }
           }
        }

I suppose the output to the array is an incorrect, but... that's still unsure.

Answer

Solution:

Your function returns null because you didn't return your array.

Modify your function like this :

function getDivisors($num) {
  for ($i=1; $i<=$num; $i++) {
     if ($num % $i == 0) {
        $divisors[] = $i;
     }
  }
  return $divisors;
}

Source