如何用逗号分隔阵列? [英] how to separate array with commas?

查看:130
本文介绍了如何用逗号分隔阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个$ _categories如阵列()

i have this $_categories as array()

< PHP的print_r($ _类别); ?> 是这样的:阵列([0] => 13 [1] => 7)

<?php print_r($_categories); ?> is this: Array ( [0] => 13 [1] => 7 )

我需要的是提取德值13和7成这种格式。(最后一个值后没有逗号)13.7

what i need is to extract de values 13 and 7 into this format: 13,7 (without comma after the last value).

我有这个code,但现在还没有......结果是:137,而不是13.7

i have this code but is not there yet... the result is: 137 and not 13,7

<?php
    if ( is_array($_categories) ) {
        foreach ($_categories as $key => $value) {
            $out = array();
            array_push($out, $value);
            echo implode(', ', $out);
        }
    }
    else {
        echo '<li>There are no saved values yet.</li>';
    }
?> 

谢谢,纳尔逊

推荐答案

直接使用

echo implode(', ', $_categories);

这篇关于如何用逗号分隔阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆