0

## php迴圈邏輯問題

``````//\$inputnumber為表單輸入傳來的數字
//定義基數
\$number1=60000;
\$number2=40000;
\$number3=20000;
if (\$inputnumber >= 0 && &lt; 10000){
\$number1 = \$number1 / 1;
\$number2 = \$number2 / 1;
\$number3 = \$number3 / 1;
}
else if (\$inputnumber >= 10000 && \$inputnumber &lt; 20000){
\$number1 = \$number1 / 2;
\$number2 = \$number2 / 2;
\$number3 = \$number3 / 2;
}
else if (\$inputnumber >= 20000 & \$inputnumber &lt; 30000)
{
\$number1 = \$number1 / 3;
\$number2 = \$number2 / 3;
\$number3 = \$number3 / 3;
}

//最後印出變動後的基數
echo \$number1;
echo \$number2;
echo \$number3;
``````

```<?php
\$inputnumber = 13000;
\$number3 = 20000 / ((int) (\$inputnumber / 10000) + 1);
echo "inputnumber:".\$inputnumber . "-----number1:" . \$number3*3 . "-----number2:" . \$number3*2 . "-----number3:" . \$number3;
?>
```

### 2 個回答

2
weiclin
iT邦高手 4 級 ‧ 2015-07-20 08:43:07

``````&lt;pre class="c" name="code">
function getNum(\$inNum)
{
echo "input \$inNum\n";
if (\$inNum >= 0) {
\$divNum = ceil((\$inNum + 1) / 10000);
if (\$divNum &lt;= 20000) {
return array(60000/\$divNum, 40000/\$divNum, 20000/\$divNum);
}
}
}

list(\$number1, \$number2, \$number3) = getNum(9999);
echo "\$number1, \$number2, \$number3";
``````

weiclin iT邦高手 4 級 ‧ 2015-07-20 21:22:11 檢舉

0

iT邦大師 1 級 ‧ 2015-07-20 03:26:57

``````&lt;pre class="c" name="code">
\$Value = 15000 ;
\$Number1 = 60000 ;
\$Number2 = 40000 ;
\$Number3 = 20000 ;
switch (\$Value > 0 ) {
case (\$Value >= 30000):
Echo "三萬以上怎麼辨???&lt;br>";
\$Nr = 1 ;
Break ;
case (\$Value >= 20000 and \$Value &lt; 30000):
\$Nr = 3 ;
Break ;
case (\$Value >= 10000 and \$Value &lt; 20000):
\$Nr = 2 ;
Break ;
case (\$Value >0 and \$Value &lt; 10000):
\$Nr = 1 ;
Break ;
}
\$Number1 = \$Number1 / \$Nr ;
\$Number2 = \$Number2 / \$Nr ;
\$Number3 = \$Number3 / \$Nr ;
Echo &lt;&lt;&lt; PrintEcho
\\$Number1 = \$Number1 &lt;BR>
\\$Number2 = \$Number2 &lt;BR>
\\$Number3 = \$Number3 &lt;BR>
PrintEcho;
``````