I’m looking to iterate through some $_POSTed variables from an HTML form. Unfortunately, I can’t figure out to access each “row” to do stuff to it.
$_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
}
Running this code currently prints nothing. Any help someone might provide to help me access each rows’ data would be greatly appreciated.
Better way is use another structure of array: