What's your reason for adding all the entries to an array and then use that in a custom table, instead of
$table = new \IPS\Helpers\Table\Db( 'customtable_log', $url, $where );
$table->selects = [ 'customtable_log.device', 'MAX(customtable_log.user_id) AS user_id'];
$table->joins = [ [ 'select' => 'GROUP_CONCAT(DISTINCT core_members.name SEPARATOR ", ") AS shared_by', 'from' => 'core_members', 'where' => 'customtable_log.user_id = core_members.member_id' ] ];
$table->groupBy = 'COUNT(customtable_log.user_id) > 1';
?
I haven't tested this, but you should be able to use the Db class even if you need to use a query out of the ordinary.