doushen9863 2016-02-28 15:36
浏览 83
已采纳

Yii2:如何在foreach循环中使用rtrim?

I'm getting images from database which holds path of the images each path is separated by ';' i need to ignore the last ';' because when it is displaying the images from db its getting last ';' and showing broken thumbnail in view

<?php
foreach (explode(';', $row['images']) rtrim($row['images'],';') as $key_img => $value_img)
{
echo Html::img(Yii::getAlias('@web').'/'.$value_img,[
' height'=> 500,
'width'=> 500,
]);
}
?> 
  • 写回答

1条回答 默认 最新

  • drhs13583567608 2016-02-28 16:24
    关注

    If you want explode the result of rtrim you shold do this way

    foreach (explode(';',  rtrim($row['images'],';')) as $key_img => $value_img)
    

    or you could need a substr

    yourString =  substr($row['images'],strlen($row['images'])- 1);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?