So if your js is inline, you can use php inside the script tag, see how:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled</title>
<link rel="stylesheet" href="css/style.css">
<link rel="author" href="humans.txt">
</head>
<body>
<?php
$cod = 23;
?>
<select name="select" class="select2<?= $cod?>" id="item1">
<option value="01">01</option>
</select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scripttype="text/javascript">
$('.selects2<?= $cod ?>').select2();
</script>
</body>
</html>
Now, if your js is inside an external file, you can create a variable in the window and retrieve it in your file, like this:
HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled</title>
<link rel="stylesheet" href="css/style.css">
<link rel="author" href="humans.txt">
</head>
<body>
<?php
$cod = 23;
?>
<select name="select" class="select2<?= $cod?>" id="item1">
<option value="01">01</option>
</select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scripttype="text/javascript">
window.classeSelect = ".select2<?= $cod ?>";
</script>
<script src="script.js"></script>
</body>
</html>
JS:
$(window.classeSelect).select2();