如何将php类数组的值从一个php文件发送到另一个php文件
我在一个php文件中有一个类数组,这个类有3个字段,我使用这些字段在一个表单中使用POST保存SELECTS和INPUT复选框的值,然后我需要将这个类数组发送到另一个php文件以处理数据如何将php类数组的值从一个php文件发送到另一个php文件,php,html,Php,Html,我在一个php文件中有一个类数组,这个类有3个字段,我使用这些字段在一个表单中使用POST保存SELECTS和INPUT复选框的值,然后我需要将这个类数组发送到另一个php文件以处理数据 <?php class info_subject{ public $code_as; public $time_as; public $selectionn_as; } $subjects[0] = new info_subject();//The onl
<?php
class info_subject{
public $code_as;
public $time_as;
public $selectionn_as;
}
$subjects[0] = new info_subject();//The only way I have seen for creating an array of classes
//is with a for loop, but if you have a better way for doing this, please let me know
$subjects[1] = new info_subject();
//here i am using the fields to save info in a form
$i=0;
echo "<form name = 'formsubjects' method='post' action='file2.php'>";
echo "<select name=\"".$subjects[$i]->time_as ."\">";
//options
echo "</select>";
echo "<input type='checkbox' name=\"".$asignaturas[$i]->selection_as."\">";
//and so on with every position of the array using $i
?>
//then there is a button to send the the dato to file2.php
//file2.php
<?php
$subjects=$_POST["$subjects"];//I am using this but i cant retrieve the fields of $subjects
?>
朋友们,我能做什么?您不能通过$\u POST提交类或数组,因为POST数组是一个只能包含简单值的数组。嗨~Jose Ricardo Citerio。我希望你能读中文 我不知道你是不是需要这样,在文件1里面存储着选择的选项选项。然后文件2接收去后处理
<?php
}
$subjects=新信息\主题
回声;
回显“代码为[名称]。>”;
//循环$subjects的选项[option]并打印k和v;like=>foreach$subjects->code_as[name]as$k=>v{echo.$v.}
回响
回显'xxx['name'].>请勾选“
?>
//然后有一个按钮将dato发送到file2.php
//file2.php
<?php
$subjects = $_POST["select_name"];
$subjects1 = $_POST["checkbox_name"];
?>而不是:
$i=0;
echo "<form name = 'formsubjects' method='post' action='file2.php'>";
echo "<select name=\"".$subjects[$i]->time_as ."\">";
//options
echo "</select>";
echo "<input type='checkbox' name=\"".$asignaturas[$i]->selection_as."\">";
挑选你需要的东西
老实说,我觉得你的问题很难理解。也许可以尝试简化您的问题,清理一些代码/格式,我们会更容易给您提供建议。您肯定应该看看MVC体系结构。这是什么伙伴?…一种编程方式,它不会让您像以前那样将HTML与PHP混合,也就是说,它不能解决您的问题。对于您的问题,我建议您创建一个返回所需变量的方法,然后在另一个文件中使用您的类并调用刚刚实现的函数。如果您有拼写错误:$asignataras[$I]->selection\u as应该是:$subject[$I]->selection\u as
$i=0;
echo "<form name = 'formsubjects' method='post' action='file2.php'>";
echo "<select name=\"".$subjects[$i]->time_as ."\">";
//options
echo "</select>";
echo "<input type='checkbox' name=\"".$asignaturas[$i]->selection_as."\">";
$i=0;
echo "<form name = 'formsubjects' method='post' action='file2.php'>";
echo "<select name=\"subjects[$i][".$subjects[$i]->time_as ."]\">";
//options
echo "</select>";
echo "<input type='checkbox' name=\"subjects[$i][".$asignaturas[$i]->selection_as."]\">";
$subjects=$_POST["subjects"];