How to join array values in PHP
php
Solution
You have to map the array values first:
echo join(',', array_map(function($item) {
return $item['cid'];
}, $arr));
Without closures it would look like this:
function get_cid($item)
{
return $item['cid'];
}
echo join(',', array_map('get_cid', $arr));
See also: `array_map()`
Problem
I have a PHP array: ``` array 0 => array 'cid' => string '18427' (length=5) 1 => array 'cid' => string '17004' (length=5) 2 => array 'cid' => string '19331' (length=5) ``` I want to join the values so I can get a string like this: ``` 18427,17004,19331 ``` I tried the `implode` PHP function, But I get an error: ``` A PHP Error was encountered ``` How can join only the values which are in `cid`?