In terms of my data structure, I have an array of communications, with each communications_id itself containing three pieces of information: id, score, and content.
I want to implode this array in order to get a comma separated list of ids, how do I do this?
From http://snipplr.com/view.php?codeview&id=10187:
For anyone else looking for an answer, this is what I was able to do:
I used this with a 3-dimensional array.
this comment based on @jon solution , just add functional code block
but i have to use loop because array_map does not accept second parameter
You can have a look to array_walk_recursive function . This is a working snippet of creating of recursive array to string conversion :
Update for PHP 5.5
PHP 5.5 introduces
array_column
which is a convenient shortcut to a whole class ofarray_map
usage; it is also applicable here.Original answer
You need to make an array of just ids out of your array of communications. Then the implode would be trivial.
Hint: the function for that is
array_map
.Solution:
Assumes PHP 5.3, otherwise you 'd have to write the callback as a string.