LoginSignup
0
0

More than 1 year has passed since last update.

【PHP】【str_replace】でforeach() 不要論

Last updated at Posted at 2022-12-09

コード

<?php
$names = '渡部,品川,滝谷,川原田,田中';
echo str_replace(',',PHP_EOL,$names);
$names = ['渡部','品川','滝谷','川原田','田中',];
echo str_replace(',',PHP_EOL,join(',',$names));
$names = ['渡部', '品川', '滝谷', '川原田', '田中'];
echo implode(PHP_EOL, $names);

結果

渡部
品川
滝谷
川原田
田中

リスト化もできる

<?php
echo '<li>'.str_replace(',','</li><li>','111,222,333').'</li>'; 

結果

<li>111</li><li>222</li><li>333</li>
0
0
4

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