我希望从 HTML 表单中遍历一些 $_POSTed 变量。不幸的是,我无法弄清楚访问每个“行”来对其进行处理。
$_POST['names'] = array('alan', 'bob', 'carl', 'dan', 'ed');
$_POST['emails'] = array('0@.com', '1@com', '2.com', '3.com', '4.com');
$data=$_POST;
foreach($data as $index=>$row){
doSomethingNames($row[$index]); //in reality, this would be a more complicated function that needs to access each row's variables, same for printEmails()
doSomethingEmails($row[$index]);
}
function doSomethingNames($row){
print_r($row['names']);// should print alan-bob-carl-dan-ed
}
function doSomethingEmails($row){
print_r($row['emails']); //should print 0.com-1.com-2.com-3.com-4.com
}
运行此代码当前不会打印任何内容。有人可能会提供任何帮助来帮助我访问每一行的数据,我们将不胜感激。