-5

I want to convert an array of this style:

Array ( [0] => Array ( [post_id] => 20752 ) [1] => Array ( [post_id] => 20753 ) ) 

into the string:

20752, 20753

How can I do this?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Quentin
  • 3
  • 1
  • http://php.net/manual/en/function.implode.php – Peter Sep 25 '17 at 09:21
  • First use `array_column()` and then `implode()`. – KIKO Software Sep 25 '17 at 09:22
  • Pure code-writing requests are off-topic on Stack Overflow -- we expect questions here to relate to *specific* programming problems -- but we will happily help you write it yourself! Tell us [what you've tried](https://stackoverflow.com/help/how-to-ask), and where you are stuck. This will also help us answer your question better. – glennsl Sep 25 '17 at 10:10

1 Answers1

1

You can use PHP array_column function with combination of implode:

implode(', ', array_column($data, 'post_id'));
gintko
  • 697
  • 8
  • 16