zoukankan      html  css  js  c++  java
  • PHP 数组拼接成字符串

    PHP【知识分享】 数组拼接成字符串

    <?php

    // 格式: 【二维数组】

    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.',');

        }

    }

  • 相关阅读:
    Spring Boot|Async
    SonarQube使用
    大数据|linux权限chmod和chown
    Spring Boot|监控-Actuator
    Docker|部署及简单使用
    Spring|IOC启动流程
    Spring|注解
    Spring|@Autowired与new的区别
    Spring|Spring MVC
    个人站点
  • 原文地址:https://www.cnblogs.com/gaohj/p/4991306.html
Copyright © 2011-2022 走看看