所以,我有一个像这样的数组:
Array ( [0] => Array ( [name] => Something ) [1] => Array ( [name] => Something else ) [2] => Array ( [name] => Something else.... ) )
是否有一种将值插入字符串的简单方法,如下所示:
echo implode(',',$array[index]['name']) // result: Something,Something else,Something else...
不使用循环来连接值,如下所示:
foreach ($array as $key => $val) { $string .= ',' . $val; } $string = substr($string,-2); // Needed to cut of the last ','
最简单的方法是,当内部数组中只有一个项目时:
$values = array_map('array_pop',$array); $imploded = implode(',$values);