您需要将 $category 设置为选项值更改此:
<option value="category">
对此:
<option value="<?=$category?>">
以下是适用于更多此类情况的示例:
<!--SELECT INPUT-->
<select id="p_category">
<option value=""> Sélectionner catégorie</option>
<?php foreach ($categories as $category): ?>
<option value="<?=$category?>"><?=$category?>
<?php endforeach;?>
</select>
<!--Container List-->
<div class="cat-container" data-id="test1">
<h1>This is Test1 Category</h1>
</div>
<div class="cat-container" data-id="Fe_Ence">
<h1>This is Fe_Ence Category</h1>
</div>
<div class="cat-container" data-id="test3">
<h1>This is test3 Category</h1>
</div>
// Javascript code
checkCategory();
$("#p_category").on('change', checkCategory)
function checkCategory() {
$('.cat-container').hide()
const selected = $('#p_category').val()
if (!selected) return;
$(`[data-id=${selected}`).show()
}