如何将post变量值传递给数组?

时间:2013-05-20 20:11:42

标签: php arrays session multidimensional-array country

我有一个代码,我想在user's select country from drop down select list时无法正常工作?提交表单后,应将值存储到courier array

例如

如果用户选择了Usa,那么Usa应该与abc courier array values匹配,如果值相互匹配,那么$_SESSION['country1']=$abc;将会创建吗?

特色:Señorio

我有两家不同的快递公司,我想根据快递公司向另一页传递国家名单?

索引页

<?php
session_start();
if(isset($_REQUEST['test']))
{
$newcountry=$_POST['country'];  

//Let's Assume Courier Companies Is Abc
$abc=array($newcountry=>'Usa',$newcountry=>'Uk');

//Let's Assume Another Courier Companies Is Xyz
$xyz=array($newcountry=>'Singapore',$newcountry=>'Germany');

$_SESSION['country1']=$abc;
$_SESSION['country2']=$xyz;

if(isset($_SESSION['country1']) && isset($_SESSION['country2'])){
header('Location:test.php'); 
}}
?>

<form method="post">
<select name="country" id="country">
<option value="Usa">Usa</option>
<option value="Uk">Uk</option>
<option value="Germany">Germany</option>
<option value="Singapore">Singapore</option>
<input type="submit" name="test" value="Submit" />

</select>
</form>

test.php的

session_start();
echo $country2=implode($_SESSION['country1']);

1 个答案:

答案 0 :(得分:0)

$newcountry=$_POST['country'];  

//Let's Assume Courier Companies Is Abc
$abc=array($newcountry=>'Usa',$newcountry=>'Uk');

//Let's Assume Another Courier Companies Is Xyz
$xyz=array($newcountry=>'Singapore',$newcountry=>'Germany');

$ abc和$ xyz的数组赋值会产生一个元素。如果选择“Usa”$ abc = array(“Usa”=&gt;“Uk”)和$ xyz = array(“Usa”=&gt;“Germany”),因为$ newcountry的值是相同的而后者值重置正式值。