如何将数组展平为值的字符串? [英] How to flatten an array to a string of the values?

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

问题描述

我有一个看起来像这样的数组.

I have an array that looks like this.

'keyvals' => 
    array
      'key1' => 'value1'
      'key2' => 'value2'
      'key3' => 'value3'

是否有一种很酷的方法可以将其展平为像'value1 value2 value3'这样的字符串?如果那里有新内容,我也可以使用PHP 5.3.

Is there a cool way to flatten it to a string like 'value1 value2 value3'? I also have access to PHP 5.3 if there's something new there.

推荐答案

$someArray = array(
  'key1' => 'value1',
  'key2' => 'value2',
  'key3' => 'value3'
);
implode(' ', $someArray); // => "value1 value2 value3"

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

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