Pre-selected with var php

Hello,
I have a PHP variable
$ marterial = 1,2,3,4;
I want to pre-selected my multiple select with these 4 id (1,2,3,4)

My select

<select id="materialS" name="materialS[]" class="form-control select2" multiple="multiple">

to retrieve my php variable

<input type="hidden" id="materialSs" name="materialSs" value="<?php echo htmlspecialchars($materialS,ENT_QUOTES,'utf-8');?>">

my script to change the dynamic select

var str = $("#materialSs").val();
$('#materialS').val(str);
$('#materialS').trigger('change');

I can’t do it
thank you for your help