Php 基于当前值的for循环步长
我已经设置了上面显示整数的循环 我希望能够根据值(Php 基于当前值的for循环步长,php,Php,我已经设置了上面显示整数的循环 我希望能够根据值($I)设置步骤 $min=100; $max=$1000; $step_值=数组( 900 => 100, 100000 => 1000 ); 对于($i=$min;$i,因为您每次都需要搜索增量,我已将增量移动到循环中,在每个循环中,它将查看步骤值列表,并对照当前值进行检查 $min = 100; $max = 10000; // Remove the $ and for testing I've increased this $ste
$I
)设置步骤
$min=100;
$max=$1000;
$step_值=数组(
900 => 100,
100000 => 1000
);
对于($i=$min;$i,因为您每次都需要搜索增量,我已将增量移动到循环中,在每个循环中,它将查看步骤值列表,并对照当前值进行检查
$min = 100;
$max = 10000; // Remove the $ and for testing I've increased this
$step_values = array(
200 => 100,
300 => 200,
2500 => 500,
5000 => 1000,
10000 => 2000
);
$credit_cost = 1; // Test value
for($i = $min; $i <= $max;) {
echo '<option value="'.$i.'">'.$i.' Credits (£'.number_format($credit_cost,2).' = £'.number_format(($credit_cost * $i)).')</option>';
foreach ( $step_values as $limit => $increment ) {
if ( $i <= $limit ) {
$i+=$increment;
break;
}
}
}
$min=100;
$max=10000;//删除$,对于测试,我增加了这个值
$step_值=数组(
200 => 100,
300 => 200,
2500 => 500,
5000 => 1000,
10000 => 2000
);
$credit\u cost=1;//测试值
对于($i=$min;$i$increment){
如果($i,因为您每次都需要搜索增量,我已经将增量移动到循环中,在每个循环中,它将查看步长值列表,并对照当前值进行检查
$min = 100;
$max = 10000; // Remove the $ and for testing I've increased this
$step_values = array(
200 => 100,
300 => 200,
2500 => 500,
5000 => 1000,
10000 => 2000
);
$credit_cost = 1; // Test value
for($i = $min; $i <= $max;) {
echo '<option value="'.$i.'">'.$i.' Credits (£'.number_format($credit_cost,2).' = £'.number_format(($credit_cost * $i)).')</option>';
foreach ( $step_values as $limit => $increment ) {
if ( $i <= $limit ) {
$i+=$increment;
break;
}
}
}
$min=100;
$max=10000;//删除$,对于测试,我增加了这个值
$step_值=数组(
200 => 100,
300 => 200,
2500 => 500,
5000 => 1000,
10000 => 2000
);
$credit\u cost=1;//测试值
对于($i=$min;$i$increment){
如果($i),这是一个非常好的代码,非常有用,谢谢!我正在尝试列出值1002003005001000150020002500 300400050006000 8000 10000
,但我想我错过了什么(这是漫长的一天!)我已将步长值更改为这个200=>100500=>2001000=>10005000=>200010000=>2000
不确定如何得到这些数字,因为当值为500时,您说增量为200(500=>200)然后它会变成700。然后它会增加到1000,这就是1700。你能检查一下你期望的数字吗。啊,不,对不起。这不是我的数字,这是我努力实现的。这是非常好的代码,非常好,谢谢!我正试着列出值1002003005001000150020002503004000,5000,6000,8000,10000
但是我想我错过了什么(这是漫长的一天!)我已经将步长值更改为这个200=>100500=>2001000=>10005000=>200010000=>2000
不确定当值为500时如何得到这些数字,你说增量是200(500=>200)然后是700。然后是1000的增量,这就是1700。你能检查一下你期望的数字吗。啊,不,对不起。这不是我的数字,这是我想要达到的
<option value="100">100 Credits (£1.00 = £100)</option>
<option value="200">200 Credits (£1.00 = £200)</option>
<option value="300">300 Credits (£1.00 = £300)</option>
<option value="500">500 Credits (£1.00 = £500)</option>
<option value="1000">1000 Credits (£1.00 = £1,000)</option>
<option value="1500">1500 Credits (£1.00 = £1,500)</option>
<option value="2000">2000 Credits (£1.00 = £2,000)</option>
<option value="2500">2500 Credits (£1.00 = £2,500)</option>
<option value="3000">3000 Credits (£1.00 = £3,000)</option>
<option value="4000">4000 Credits (£1.00 = £4,000)</option>
<option value="5000">5000 Credits (£1.00 = £5,000)</option>
<option value="6000">6000 Credits (£1.00 = £6,000)</option>
<option value="8000">8000 Credits (£1.00 = £8,000)</option>
<option value="10000">10000 Credits (£1.00 = £10,000)</option>