您的位置:首页 > 编程语言 > PHP开发

数组拼接成字符串

2016-07-19 18:02 399 查看

格式: 【二维数组】

Array

(

   [0] => Array

       (

           [topicid] => 1

       )

   [1] => Array

       (

           [topicid] => 2

       )

   [2] => Array

       (

           [topicid] => 6

       )

)

//方法一:

$topicid = ' '; //变量赋值为空

//用foreach 遍历下二维数组

foreach($arrs as $key=>$vals){

    $topicid.=$vals['topicid'].',';

}

// 使用 rtrim() 函数从字符串右端删除字符:

$topicid = rtrim($topicid, ',');

echo $topicid;

结果: 1,2,6

// 方法二:

foreach($ProTopicid as $valueId){

    $string  = '';

    foreach($valueId as $v){

        $string.= rtrim($v.',');

    }

}

结果: 1,2,6
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php