我已经写了一个脚本来为我自动化一些计算。这很简单。 1 * 3 = 3 2 * 3 = 6 3 * 3 = 9等等。当答案(产品)超过一位数字时,我希望它添加答案的数字。 3 * 4 = 12 || 1 + 2 = 3。 我希望它自动添加答案,如果它不止一个数字,无论添加答案的次数多于一个数字。 ,当你达到13 * 3 = 39 ||时3 + 9 = 12 || 1 + 2 = 3 目前我的代码不循环,我不知道如何使它在这里循环。我怎样才能更有效地循环这个过程
http://screencast.com/t/MdpQ9XEz
另外,不加入了超过2位的答案见34 * 3 = 102。在这里任何帮助,让它无限添加将是伟大的。 随着每条生产线的答案变得越来越大,所以它应该在答案中增加尽可能多的数字。
这里是我的代码:
$i = 1; //Start with one
function count_digit($number) {
return strlen((string) $number);
};
while($i < 500){
$product = $i * 3; //Multiply set
$number_of_digits = count_digit($product); //calls function to count digits of $sum
if($number_of_digits > 1){ //if $sum has more than one digit add the digits together
$addproduct = strval($product);//seperates the digits of $sum
$ii = 0;
while($ii <= $number_of_digits -1){
$io = $ii + 1;
if($io < $number_of_digits){
$one = intval($addproduct[$ii]);
$two = intval($addproduct[$io]);
$sum = $one + $two;
print($i . ' * 3 = ' .$product. ' || ' .$one. ' + ' .$two. ' = ' .$sum. '<br>');
};$ii++;
};
}else{
Print ($i . ' * 3 = ' .$product.'<br>'); //Print Set
};
$i++; //add one
}