Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于HTML、PHP的回音信息_Php_Html_Echo - Fatal编程技术网

基于HTML、PHP的回音信息

基于HTML、PHP的回音信息,php,html,echo,Php,Html,Echo,我到处寻找答案 我希望根据他们在html表单中输入的年龄来回显消息 有人知道怎么做吗?谢谢 您正在询问如何根据测试变量提供不同的输出 解决方案 您需要一个开关来测试您的变量,并使用适用于您的开关的情况 switch(intAge){ case 0: echo "Message if they are under 1 yrs old"; break; case 1: echo "Message if they are 1 yrs old";

我到处寻找答案

我希望根据他们在html表单中输入的年龄来回显消息

有人知道怎么做吗?谢谢 您正在询问如何根据测试变量提供不同的输出

解决方案 您需要一个开关来测试您的变量,并使用适用于您的开关的情况

switch(intAge){
    case 0:
        echo "Message if they are under 1 yrs old";
    break;
    case 1:
        echo "Message if they are 1 yrs old";
    break;
    default:
        echo "Message if they are neither 0 or 1";
    break;
}
另一种方法是使用年龄范围

switch(true){
    case (intAge >=0 && intAge <=5):
        echo "Message for a toddler";
    break;
    case (intAge >5 && intAge <=12):
        echo "Message for primary school age";
    break;
    case (intAge > 12 && intAge <=16):
        echo "Message for highschooler";
    break;
    case (intAge >=18 && intAge <=65):
        echo "Message for working age";
    break;
    case (intAge > 65):
        echo "Message for a pensioner";
    break;
    default:
        echo "Message for a 17 yr old or when a value is not an integer";
    break;
}
你没查过那张支票吗?