簡體   English   中英

顯示姓名列表並使用 php 在列表中的姓氏中添加逗號 & 和

[英]Displaying a list of names and adding a comma & and to the last name on the list using php

我想顯示一個名字列表並用逗號分隔它們,姓氏應該使用 php 用“和”分隔。 請我需要幫助。

這是我的代碼:

    <?php 
                  $bdaypersoname="";
                  do {
                     $bdaypersoname .= $row_Recordset2['Name']." , ";

                      } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); 
                      $bdaypersoname= rtrim($bdaypersoname, " , ");
                      echo $bdaypersoname;
                    ?>
    </p>

像這樣嘗試,使用一些演示名稱

$array = ['Alex','Bob','Collins','Danny'];
echo join(' and ', array_filter(array_merge(array(join(', ', array_slice($array, 0, -1))), array_slice($array, -1)), 'strlen'));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM