Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.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
Php forminput中的多维数组_Php_Arrays_Forms_Multidimensional Array - Fatal编程技术网

Php forminput中的多维数组

Php forminput中的多维数组,php,arrays,forms,multidimensional-array,Php,Arrays,Forms,Multidimensional Array,我认为我的解决方案是在多维数组中,但是如何 如果我有以下(或类似)HTML表单(例如简化) 很抱歉听起来很傻,但我还没有用多维数组的“Erika”时刻 如果您有任何建议,我将不胜感激。$\u POST['Postage']不是多维数组。如果您使用var_dump($_POST['Postage']),您可以很容易地看到它;它只是选择中所有选定索引的数组: array(3) { [0]=> string(1) "1" [1]=> string(3) "1

我认为我的解决方案是在多维数组中,但是如何

如果我有以下(或类似)HTML表单(例如简化)

很抱歉听起来很傻,但我还没有用多维数组的“Erika”时刻


如果您有任何建议,我将不胜感激。

$\u POST['Postage']
不是多维数组。如果您使用var_dump($_POST['Postage']),您可以很容易地看到它;它只是选择中所有选定索引的数组:

array(3) {
    [0]=>
    string(1) "1"
    [1]=>
    string(3) "1"
    [2]=>
    string(3) "1"
  }
以下是我为测试输入的内容:

这里我使用for循环得到了邮资和相关价格:

<?php
$n = count($_POST['Postage']);
for ($i = 0; $i < $n; ++$i)
{
    print $_POST['Postage'][$i] . " " . $_POST['PostagePrice'][$i] . "<br>";
}

考虑您的输入数组,如下所示:

<?
//Let your inputs be Postage1, Price1, Postage2, Price2...
//Then your Received POST will be..
$_POST = Array(
            "Postage" => Array( 0 => 'Postage1', 1 => 'Postage2', 2 => 'Postage3'),
            "PostagePrice"=> Array( 0 => 'Price1', 2 => 'Price2', 3 => 'Price3')
            );
//Now, you can see that index 0 points to a price of POSTAGE and so on 1 and 2..

//Store corresponding values in an Array.
$store = Array();

foreach($_POST['Postage'] as $PostateID=>$PostageOption){
    $store[$PostageOption] = $_POST['PostagePrice'][$PostateID];
}

print_r($store);

?>



通过这种方式,您将在该数组中关联邮资和邮资价格。

任何您想要的结果示例?您可以用一个您想要返回的示例输出数组澄清一下吗?“Erika”,这是“Eureka”的mondegreen吗?这看起来像是一个创建可能邮资选项的表单,可能是针对一种产品,这意味着邮资选项并不是每个产品都有相同的价格。如果我说的话有一半是对的,那么你试图实现这一目标的方式看起来不是很理想。告诉我们你想做什么,也许我们可以为你找到一个更简单的解决方案。是的,弗洛斯库斯,你说得对了一半以上!我正在尝试做类似易趣如何做邮资。这样“用户”就可以设置每种产品的邮资,邮资不同,邮资选项也不同。谢谢,是的,我有点困惑,这是否是一个多维数组(我认为结果可能是多维的…)。那么,如何将结果设置为“1邮资1/24小时交付5.00美元”?或“2 48小时交货3.00美元”,etc@Ford收到邮件ID后,需要从数据库中输入邮件的名称和投递时间。
<?php
$n = count($_POST['Postage']);
for ($i = 0; $i < $n; ++$i)
{
    print $_POST['Postage'][$i] . " " . $_POST['PostagePrice'][$i] . "<br>";
}
1 1
2 2
2 3
<?
//Let your inputs be Postage1, Price1, Postage2, Price2...
//Then your Received POST will be..
$_POST = Array(
            "Postage" => Array( 0 => 'Postage1', 1 => 'Postage2', 2 => 'Postage3'),
            "PostagePrice"=> Array( 0 => 'Price1', 2 => 'Price2', 3 => 'Price3')
            );
//Now, you can see that index 0 points to a price of POSTAGE and so on 1 and 2..

//Store corresponding values in an Array.
$store = Array();

foreach($_POST['Postage'] as $PostateID=>$PostageOption){
    $store[$PostageOption] = $_POST['PostagePrice'][$PostateID];
}

print_r($store);

?>
<?PHP
$final = array_combine($_POST['Postage'], $_POST['PostagePrice']);
?>