1

I got the next array:

    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 )

)

How am I supposed to get all 'address'es in a variable as a string separated by comma?

something like this

$string = "1stadress, 2ndaddress, 3ndadress' etc

I tried:

$comma_separated = implode(",", $row['address']); // where $ row is the array above

and it failed.

Cœur
  • 37,241
  • 25
  • 195
  • 267
JBan321
  • 49
  • 6

2 Answers2

4

You can use array_column and implode

echo implode(',',array_column($myarray,'address'));
Akshay Hegde
  • 16,536
  • 2
  • 22
  • 36
0

Loop though array and collect the relevant members, I'd perefer using untermidiate array this way it can be reused if needed later

$buffer = [];
foreach($myArray as $id=>$data){
  $buffer[] = $data['address'];
}
$output = implode(',',$buffer);
George Dryser
  • 322
  • 1
  • 7