获取某个正整数的全部质因数

2023-02-09 01:51:05   php分享记录

 

  1. $tmp = [];
  2. for ($i = 2; $i * $i <= $num; ++$i) {
  3. while (0 === $num % $i) {
  4. $num = $num / $i;
  5. $tmp[] = $i;
  6. }
  7. }
  8. $tmp[] = $num;