简单的php字符串问题,
我对一段php代码很感兴趣,我的问题是: 我正在使用php if和elseif来展示如下内容:简单的php字符串问题,,php,if-statement,Php,If Statement,我对一段php代码很感兴趣,我的问题是: 我正在使用php if和elseif来展示如下内容: <?php $test_a = 0 to 10; (My problem) $test_b = 11 to 20; (My problem) $test_c = 21 to 30; (My problem) $test = 50; (random value) $something = 12; $something_b = 5; $something
<?php
$test_a = 0 to 10; (My problem)
$test_b = 11 to 20; (My problem)
$test_c = 21 to 30; (My problem)
$test = 50; (random value)
$something = 12;
$something_b = 5;
$something_c = 15;
?>
<?php
if($test>=$test_a){
echo $something;
}elseif ($test=<$test_b) {
echo $something_b;
}elseif (test=<$test_c) {
echo $something_c;
}
?>
我的问题是如何使用if/elseif处理范围
谢谢 这显然是无效的语法。这实际上只是一个基本的if/else语句:
if($test>=0 && $test <=10){
echo $something;
}elseif ($test>=11 && $test <=20) {
echo $something_b;
}elseif ($test>=21 && $test <=30) {
echo $something_c;
}
如果($test>=0&&$test=11&&$test=21&&$test将变量设置到每个范围的顶部:
$test_a = 10;
$test_b = 20;
$test_c = 30;
if ($test <= $test_a) {
echo $something;
} elseif ($test <= $test_b) {
echo $something_b;
} elseif ($test <= $test_c) {
echo $something_c;
}
$test_a=10;
$test_b=20;
$test_c=30;
如果($test 20,'message'=>$something_b),
数组('limit'=>30,'message'=>$something\u c)
);
foreach($tests作为$curtest){
如果($test)有一个问题阻碍了你如何使用它吗?或者你只是不知道?对不起,我的错误…我不知道,但看起来很简单,就像下面的dude answers=P一样
$tests = array (array ('limit' => 10, 'message' => $something),
array ('limit' => 20, 'message' => $something_b),
array ('limit' => 30, 'message' => $something_c)
);
foreach ($tests as $curtest) {
if ($test <= $curtest['limit']) {
echo $curtest['message'];
break;
}
}