如何在PHP中将数组转换为字符串? [英] How to convert an array to a string in PHP?

查看:81
本文介绍了如何在PHP中将数组转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于下面的数组;获取数组值并将其存储为逗号分隔的字符串的最佳方法是什么?

For an array like the one below; what would be the best way to get the array values and store them as a comma-separated string?

Array ( [0] => 33160,
        [1] => 33280,
        [2] => 33180,
        [3] => 33163,
        [4] => 33181,
        [5] => 33164,
        [6] => 33162,
        [7] => 33179,
        [8] => 33154,
        [9] => 33008,
        [10] => 33009,
        [11] => 33161,
        [12] => 33261,
        [13] => 33269,
        [14] => 33169,
        [15] => 33022,
        [16] => 33141,
        [17] => 33168,
        [18] => 33020,
        [19] => 33023,
        [20] => 33019,
        [21] => 33153,
        [22] => 33238,
        [23] => 33138,
        [24] => 33167,
        [25] => 33082,) 

推荐答案

我将其转换为CSV格式,如下所示:

I would turn it into CSV form, like so:

$string_version = implode(',', $original_array)

您可以通过以下操作将其调回:

You can turn it back by doing:

$destination_array = explode(',', $string_version)

这篇关于如何在PHP中将数组转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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