我想在字符串赋值期间添加空格,如:
$movie_genre.= $row["movie_genre"]." ";
它应该显示genre1 genre2 genre3等等。这三种类型之间的单一空间是必需的。目前它正在显示genre1genre2genre3
答案 0 :(得分:1)
收集数组&然后使用implode
:
{// your loop starts
$movie_genre[] = $row["movie_genre"];
}//// your loop ends
echo implode(" ", $movie_genre);
答案 1 :(得分:0)
@ MuhammadMuazzam,请查看以下代码。
//Suppose your data array like below.(Below is sample example)
$dataArray = array('data1','data2','data3');
$numItems = count($dataArray);
$i = 0;
$movie_genre = '';
foreach($dataArray as $value)
{
if(++$i === $numItems) {
$movie_genre.= $value;
} else {
$movie_genre.= $value." ";
}
}
echo $movie_genre;
答案 2 :(得分:0)
您现有的代码非常完美,
只需添加一行rtim()
$movie_genre.= $row["movie_genre"] . " ";
$movie_genre = rtrim($movie_genre);