I've got associative array with results from database containing data like in following structure:
$arr[0] = Array("id"=>4, "otherdata"=>"something");
$arr[1] = Array("id"=>6, "otherdata"=>"something else");
$arr[2] = Array("id"=>15, "otherdata"=>"something totally different");
I would like to implode data that is only in id key for each $arr entry, so that final imploded string is 4,6,15 (gluded with ,).
Right now I've got some solutions:
but neither of them I am happy of.
Is there any other simple way to achieve desired result?
The 4th solution:
echo implode(',', array_column($arr, 'id'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With