Php 如何将post变量值传递到数组中?

Php 如何将post变量值传递到数组中?,php,arrays,session,multidimensional-array,country,Php,Arrays,Session,Multidimensional Array,Country,我有一个代码工作不正常,我想在用户从下拉选择列表中选择国家/地区时删除该代码?提交表单后,值应存储到信使数组中 例如 <?php session_start(); if(isset($_REQUEST['test'])) { $newcountry=$_POST['country']; //Let's Assume Courier Companies Is Abc $abc=array($newcountry=>'Usa',$newcountry=>'Uk'); //L

我有一个代码工作不正常,我想在
用户从下拉选择列表中选择国家/地区时删除该代码
?提交表单后,值应存储到
信使数组中

例如

<?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>
如果用户选择了Usa,则Usa应与abc courier数组值匹配如果值相互匹配,则
$\u会话['country1']=$abc将被创建吗

女士

我有两个不同的快递公司,我想通过国家名单根据快递公司的另一页

索引页

<?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>

您对$abc和$xyz的数组赋值将产生一个元素。如果选择“Usa”$abc=array(“Usa”=>“Uk”)和$xyz=array(“Usa”=>“Germany”)作为$newcountry的值相同,且后者的值重置为正式值。

当i
echo$country2=内爆($U会话['country1')
测试页面上
然后它会同时显示usauk,但我希望然后用户或客户选择国家/地区,然后国家/地区值应检入数组,然后它将是由用户或客户选择的单一国家/地区?
$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');