我得到了下一个数组:
Array (
[0] => Array ( [email] => xasxxxxxx@yahoo.com [btc] => 0.00287896 [tn] => 6.615 [address] => 2BY4HM [status] => pending )
[1] => Array ( [email] => xxxxx@yahoo.com [btc] => 0.04000 [tokens_given] => 5 [address] => xxXXxxxxxaaaxxXs [status] => pending )
[2] => Array ( [email] => xsxxxx@yahoo.com [btc] => 0.04000 [tokens_given] => 5 [address] => xxXXxxxxxaaaxxXs [status] => pending )
[3] => Array ( [email] => xssasas5@yahoo.com [btc] => 0.04000 [tokens_given] => 5 [address] => xxXXxxxxxaaaxxXs [status] => pending )
[4] => Array ( [email] => xxxxxx@yahoo.com [btc] => 0.04000 [tokens_given] => 5 [address] => xxXXxxxxxaaaxxXs [status] => pending )
)
我如何将变量中的所有'地址'作为以逗号分隔的字符串?
类似这样的事情
$ string =“1stadress,2ndaddress,3ndadress”等
我试过了:
$comma_separated = implode(",", $row['address']); // where $ row is the array above
它失败了。
答案 0 :(得分:4)
您可以使用array_column和implode
echo implode(',',array_column($myarray,'address'));
答案 1 :(得分:0)
循环通过数组并收集相关成员,我可以使用不明确的数组,这样可以在以后需要时重复使用
$buffer = [];
foreach($myArray as $id=>$data){
$buffer[] = $data['address'];
}
$output = implode(',',$buffer);