PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 28: Write a PHP program to print the sum of digits of an integer.


<!DOCTYPE html>
	<title>PHP Programs</title>
		$num = 18543;  
		$sum=0; $remain=0;  

  		for ($i =0; $i<=strlen($num);$i++)  
   			$sum = $sum + $remain;  
 		echo "Sum of digits 18543 is $sum";  

If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.