PHP开关语句
来源:百度知道 编辑:UC知道 时间:2024/05/18 11:10:23
开关语句
1)建立select.php文件;
2)将select.htm提交的国家存入$country变量;
3)判断$country的值,若为1则输出“Chinese”,2则输出“American”,3则输出“Japanese”;
4)否则,输出“Please select a country.”,并用header()设置三秒后跳转回select.htm(注意header()的位置);
5)使用一个数组实现上述功能,存为select2.php(1=>"Chinese")
我写的是
select.php:
<?php
header("refresh:3;url=http://localhost/select.htm");
if($country="1")
echo "Chinese";
if($country="2")
echo "American";
if($country="3")
echo "Japanese";
else echo "Please select a country.";
?>
select2.php:
<?php
$country=array(1=>"Chinese",2=>"American",3=>"Japanese")
?>
无论我在select.htm的表单里选择哪个,都会同时显示3个国家
还有为什么要建立一个select2.php?
1)建立select.php文件;
2)将select.htm提交的国家存入$country变量;
3)判断$country的值,若为1则输出“Chinese”,2则输出“American”,3则输出“Japanese”;
4)否则,输出“Please select a country.”,并用header()设置三秒后跳转回select.htm(注意header()的位置);
5)使用一个数组实现上述功能,存为select2.php(1=>"Chinese")
我写的是
select.php:
<?php
header("refresh:3;url=http://localhost/select.htm");
if($country="1")
echo "Chinese";
if($country="2")
echo "American";
if($country="3")
echo "Japanese";
else echo "Please select a country.";
?>
select2.php:
<?php
$country=array(1=>"Chinese",2=>"American",3=>"Japanese")
?>
无论我在select.htm的表单里选择哪个,都会同时显示3个国家
还有为什么要建立一个select2.php?
if 里的”=" 应该换成 “==”;
select2.php
<?php
$country = array(1=>"chinese",2=>"american",3=>"japanese");
$result=$_REQUEST['result'];
while(list($k,$v)=each($country)){
if($result==$k){
echo $v;
}
}
//或者换成foreach();
foreach($country as $k=>$v){
if($result==$k){
echo $v;
}
}
?>
可不可以把select.htm的代码发出来看下
搞不懂为什么要这么写,变量country已经被定义成一个数据了,那select.php里面引用是不是要加索引
建议你先看看手册