mirror of
https://github.com/TheAlgorithms/PHP.git
synced 2025-07-10 03:26:19 +02:00
22 lines
418 B
PHP
22 lines
418 B
PHP
<?php
|
|
|
|
/**
|
|
* This function checks if given number is Armstrong
|
|
* e.g. 153
|
|
* @param integer $input
|
|
* @return boolean
|
|
*/
|
|
function isNumberArmstrong(int $input): bool
|
|
{
|
|
$arr = array_map('intval', str_split($input));
|
|
$sumOfCubes = 0;
|
|
foreach ($arr as $num) {
|
|
$sumOfCubes += $num * $num * $num;
|
|
}
|
|
if ($sumOfCubes == $input) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|