Return single column from a multi-dimensional array
Quite simple:
$input = array( array( 'tag_name' => 'google' ), array( 'tag_name' => 'technology' ));echo implode(', ', array_map(function ($entry) { return $entry['tag_name'];}, $input));
and new in php v5.5.0, array_column
:
echo implode(', ', array_column($input, 'tag_name'));
Although this question is related to string conversion, I stumbled upon this while wanting an easy way to write arrays to my log files. If you just want the info, and don't care about the exact cleanliness of a string you might consider:
json_encode($array)
array_map
is a call back function, where you can play with the passed array.this should work.
$str = implode(',', array_map(function($el){ return $el['tag_id']; }, $arr));