0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【PHP】PHPで<br>を最後に出力しない方法

Last updated at Posted at 2022-07-22

コード1

<?php
$contents = ['ナルト','サスケ','我愛羅','ボルト'];
$list = '';
foreach($contents as $chara){
    $list .= !empty($list) ? '<br>':'';
    $list .= $chara;
}
echo $list;

結果

ナルト<br>サスケ<br>我愛羅<br>ボルト

コード2

<?php
$contents = ['ナルト','サスケ','我愛羅','ボルト'];
$br = '';
foreach($contents as $chara){
    echo $br?:'';
    echo $chara;
    $br = $br?:'<br>';
} 

結果

ナルト<br>サスケ<br>我愛羅<br>ボルト
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?