如果我有几个需要相同内容的类型,如何用<php if?>显示相同的内容

it may be easy answer but I'm stuck in one of my project in

I want to show text if few of my collection or function are in there , sorry for my question I'm not sure how to call them.

here's what I mean

<?php if($doc->type == "mp3"): ?>
 <p> text and some other html here </p>
<?php endif; ?>

I want here to find few of "dic types" and to show the same I can do them one by one but it will be load of codes and i think it may be some solutions like:

<?php if($doc->type == "mp3", "mp4", "doc" etc....): ?>
 <p> text and some other html here </p>
<?php endif; ?>

I want to chose between few types and show same text ,, My solutions for now is to add them one by one

<?php if($doc->type == "mp3"): ?>
 <p> text and some other html here </p>
<?php endif; ?>

<?php if($doc->type == "mp4"): ?>
 <p> text and some other html here </p>
<?php endif; ?>

<?php if($doc->type == "doc"): ?>
 <p> text and some other html here </p>
<?php endif; ?>

If is any way how to do it it would be great and really appreciated

Thank you

You have multiple ways to do it. One of the simpler is to use in_array

<?php if(in_array($doc->type, ['doc', 'mp3', 'mp4'])): ?>
 <p> text and some other html here </p>
<?php endif; ?>

Use a SWITCH case:

Manual: http://php.net/manual/en/control-structures.switch.php

Example:

<?php
switch ($i) {
    case "apple":
        echo "i is apple";
        break;
    case "bar":
        echo "i is bar";
        break;
    case "cake":
        echo "i is cake";
        break;
}
?>

Take a look at the switch() control structure:

The statement list for a case can also be empty, which simply passes control into the statement list for the next case.

<?php
switch ($i) {
case 0:
case 1:
case 2:
    echo "i is less than 3 but not negative";
    break;
case 3:
    echo "i is 3";
}
?>

What about using logical operators (|| for 'OR', && for 'AND') to combine several conditions in the same expression?

<?php if($doc->type == "mp3" || $doc->type == "mp4"): ?>
 <p> text and some other html here </p>
<?php endif; ?>