删除foreach循环的最后一个字符串值

问题描述 投票:0回答:1

这是我的代码,它从.xls fil中读取数据并将其显示在网站上:

$s = explode("@@",$rowData[$x][6]); //read data from .xls file, @@ as delimiter
      foreach ( $s as $element )  {
       echo '<li> <i class="fa fa-check" aria-hidden="true"></i>';
       echo print_r($element,true).PHP_EOL;
         } //end foreach

。xls文件的外观如下enter image description here

如您在图片中所见,Resp&Req列使用'@@'作为分隔符,而我的foreach循环将最后一个'@@'标识为新行

enter image description here

我是一个新手,我想不出删除最后一个循环的方法,感谢您的提前帮助!

php html phpexcel
1个回答
0
投票

您不需要使用unset功能。将$s = explode("@@",$rowData[$x][6]);替换为$s = explode("@@",trim($rowData[$x][6], '@@'));

© www.soinside.com 2019 - 2024. All rights reserved.