Why is the data from POST serial?

if there is a problem with the loop, how can there be so many lines for the second time

Why is the data from POST serial? why is the data from the previous row read? I got the data by reading the Excel table

I just want to read every row of Excel data instead of finding a serial solution

<?php
header("Content-Type: text/html; charset=utf-8");
error_reporting(E_NOTICE);

define("ROOT",dirname(__FILE__)."/");

if ((($_FILES["file"]["type"] == "application/vnd.ms-excel")||($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))&& ($_FILES["file"]["size"] < 20000))
{
    if ($_FILES["file"]["error"] > 0)
    {
        echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
    else
    {
        if (!empty($_FILES)) {
            $fileInfo = $_FILES["file"];
            //echo "
";
            //print_r($fileInfo);
            //echo "
"; $fileName = $fileInfo ["name"]; $fileType = $fileInfo ["type"]; $fileTmpName = $fileInfo ["tmp_name"]; $fileError = $fileInfo ["error"]; $fileSize = $fileInfo ["size"]; If ($fileError = = UPLOAD_ERR_OK) { If (move_uploaded_file ($fileTmpName,iconv ("utf-8","gb2312","./uploads/".$fileName) { $fileDir = dirname (_ _ FILE__); Echo "uploaded successfully". "\ n < br/ >\ n < br/ >"; / / doExcel (iconv ("utf-8","gb2312","./uploads/".$fileName)); $file_types = explode (".", $_ FILES ["file"] [" name"]); $file_type = $file_types [count ($file_types)-1]; $ExcelToArrary = new ExcelToArrary (); / / instantiation $res = $ExcelToArrary- > read (iconv ("utf-8","gb2312","./uploads/".$fileName), "UTF-8", $file_type); / / print_r ($res); DoData ($res); } else { Echo "upload failed"; } } else { Switch ($fileError) { Case 1: Echo "uploaded files exceed the limit of upload.max.filesize in php.ini"; Break; Case 2: Echo "file exceeds the MAX_FILE_SIZE limit of the form"; Break; Case 3: Echo "part of the form is uploaded"; Break; Case 4: Echo"no uploaded file found"; Break; Case 6: Echo"no temporary files found"; Break; Case 7: Echo "file write failed"; Break; Case 8: Echo "php file upload extension is not open"; Break; Default: Echo "unknown error, please contact the administrator, happy@13.com"; Break; } } } else { Echo "unknown error"; } } } Else { Echo $_ FILES ["file"] ["type"]; / / application/vnd.ms-excel Echo "Invalid file"; } Function doData ($data) { / / print_R ($data); / / print_R ($data [1]); $email = []; $bodyh = ""; Foreach ($data as $key = > $value) { / / print_r ($key); / / Line number / / print_r ($value); $len = count ($value); If ($key==1) { $title = $value; / / echo $value [0]. $value [1]. $value [2]. "\ n < br/ >"; } If ($key > 1) { / / echo $value [0]. $value [1]. $value [2]. "\ n < br/ >"; $bodyys = ""; For ($iTuno / investors / I < $len;$iPP) { $telTo = ""; $mailTo = ""; / / pseudo code is written by itself. / / if ($value [$I] = = "Mobile number feature") / / { / / $telTo = "18600806920"; / /} / / if ($value [$I] = "mailbox characteristics") / / { / / $mailTo = "xx@qq.com"; / /} / / pseudo code is written by itself. $bodyys = $bodyys.$title [$I]. ":". $value [$I]; Echo "< table style="border:1px solid red" > < tr > < td >". $title [$I]. ":". $value [$I]. "< / tr > < / td > < / table >"; / /-sharp-sharp is convenient to see the effect } $bodyh=$bodyh.$bodyys; $body [] = $bodyh; / / var_dump ($bodyh); $email [] = $data [$key] [2]."@ qq.com"; $bodyh = preg_split ("^ [0-9] * $", $bodyh); Echo "\ n < br/ >"; / / var_dump ($email); / / send email or text message below / / doMail ("payroll", $body, "mailbox regularly matches $mailTo"); / /-sharp-sharp / / send email or text message above } } Echo"< form action= "email.php" method= "POST" >"; Foreach ($email as $keyy = > $value) { Echo"< input type= "hidden" name= "body []" value= ". $body [$keyy]."" >"; Echo"< input type= "hidden" name= "email []" value= ". $value."" >"; } Echo"< input type= "submit" value= "send mail" >"; Echo"< / form >"; } Class ExcelToArrary { Public function _ _ construct () { Require_once "PHPExcel-1.8/Classes/PHPExcel.php"; Require_once "PHPExcel-1.8/Classes/PHPExcel/IOFactory.php"; } Public function read ($filename,$encode,$file_type) { If (strtolower ($file_type) = "xls") / / determine whether the excel table type is 2003 or 2007 { Require_once "PHPExcel-1.8/Classes/PHPExcel/Reader/Excel5.php"; $objReader =\ PHPExcel_IOFactory::createReader ("Excel5"); } elseif (strtolower ($file_type) = = "xlsx") { Require_once "PHPExcel-1.8/Classes/PHPExcel/Reader/Excel2007.php"; $objReader =\ PHPExcel_IOFactory::createReader ("Excel2007"); } $objReader- > setReadDataOnly (true); $objPHPExcel = $objReader- > load ($filename); $objWorksheet = $objPHPExcel- > getActiveSheet (); $highestRow = $objWorksheet- > getHighestRow (); $highestColumn = $objWorksheet- > getHighestColumn (); $highestColumnIndex =\ PHPExcel_Cell::columnIndexFromString ($highestColumn); $excelData = array (); For ($row = 1; $row < = $highestRow; $rowPP) { For ($col = 0; $col < $highestColumnIndex; $colPP) { $excelData [$row] [] = (string) $objWorksheet- > getCellByColumnAndRow ($col, $row)-> getValue (); } } Return $excelData; } } ? >

Php
May.22,2021

has the text box name of [], which means that the array is merged.


try to use the array form directly, do not leave blank.

such as body [1] , body [2] instead of body [] .

also, post the code later, do not take screenshots, the screenshots are all pasted.

```

it is better to post a complete code, the screenshot can only be seen in part. If the above is also a foreach loop, you can put $email and $body in an array with $key, like this

$body[$key]['body']=$bodyh;
$body[$key]['email']=$data[$key][2].'qq.com';

then the following loop can be like this:

foreach($body as $key=>$value){
    echo ...$value['email'];//
    echo ...$value['body'];
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e58696-449f2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e58696-449f2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?