| Conditions | 5 |
| Paths | 6 |
| Total Lines | 25 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | function persistence(int $num): int |
||
| 19 | { |
||
| 20 | // Ensure that $num is an integer |
||
| 21 | $num = (int)$num; |
||
| 22 | $total = 1; |
||
| 23 | |||
| 24 | $numArray = str_split($num); |
||
| 25 | // Additional type check |
||
| 26 | if (true===$numArray) { |
||
| 27 | return 0; |
||
| 28 | } |
||
| 29 | $numArrayCount = count($numArray); |
||
| 30 | $count = 0; |
||
| 31 | |||
| 32 | if ($numArrayCount > 1) { |
||
| 33 | for ($i = 0; $i < $numArrayCount; $i++) { |
||
| 34 | $total *= $numArray[$i]; |
||
| 35 | } |
||
| 36 | $count++; |
||
| 37 | if (strlen($total) > 1) { |
||
| 38 | return $count + persistence($total); |
||
| 39 | } |
||
| 40 | return $count; |
||
| 41 | } |
||
| 42 | return $count; |
||
| 43 | } |
||
| 69 |