首頁 >後端開發 >php教程 > PHP删除指定字符。该如何解决

PHP删除指定字符。该如何解决

WBOY
WBOY原創
2016-06-13 13:36:32800瀏覽

PHP删除指定字符。

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$d = array(
  0 => array(
    'a' => string 'Days_3' (length=6)
    'b' => string '3 Days' (length=6)
  )
  1 => array(
    'a' => string 'Days_7' (length=6)
    'b' => string '7 Days' (length=6)
  )
  2 => array(
    'a' => string 'Days_14' (length=7)
    'b' => string '14 Days' (length=7)
  )
  3 => array(
    'a' => string 'Days_30' (length=7)
    'b' => string '30 Days' (length=7)
  )
  4 => array(
    'a' => string 'Days_60' (length=7)
    'b' => string '60 Days' (length=7)
  ));
foreach($d as $v)
{
    echo ltrim($v['a'],"Days_").",";
}



输出的 3,7,14,3,60, ,现在用什么方法能把最后一个","去掉,结果:3,7,14,3,60



------解决方案--------------------
变通一下
PHP code
$ch = '';
foreach($d as $v)
{
    echo $ch . ltrim($v['a'],"Days_");
    $ch = ',';
}
<br><font color="#e78608">------解决方案--------------------</font><br>substr($str,0,-1)或者放入数组中。再用implode连接 <div class="clear">
                 
              
              
        
            </div>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn