Pre-selected with var php

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();

I can’t do it
thank you for your help