Home  >  Article  >  php教程  >  Calculate 1+12+123+1234+12345+...+1234567

Calculate 1+12+123+1234+12345+...+1234567

WBOY
WBOYOriginal
2016-08-10 08:49:223412browse
跳至 [1] [全屏预览]
<?
	/*
		作者: shyhero
		邮箱: shyhero@outlook.com
		Q  Q: 1757424878
	*/
	//  计算1+12+123+1234+12345+...+1234567
	
	
	for($i=1;$i<=7;$i++){
		$str .= $i;
	}
	$str = (int)$str;
	var_dump($str);
	
	$sum = 0;
	
	for($i=$str;$i>=1;$i=(int)($i/10)){
		$sum += $i;
	}
	echo $sum;
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn