set_multiselect in form_helper and Form_validation

I found useful to write these functions, to automatically fill a multiselect in a view, using this kind of code:

<?= form_multiselect( 'groups[]', $groups, set_multiselect( 'groups', $selected_groups ) ) ?>