如何创建一个从代码中获取参数并返回字符串的函数?

So, I've been trying to learn PHP. I've got an assignment where I'm supposed to make a list of products with prices, and depending on what day it is, it's supposed to give you a discount. That works so far. However, one thing i'm trying to do is to not echo the result directly in the code; I want to create a function that takes the necessary parameters (Taste, Price, Amount) and returns a formatted string. I haven't been able to do this, despite trying a lot. Here's the code I have. This is the first time i'm using Stack Overflow, so forgive me if i didn't type it in correctly.

<?php
    $donuts = array(
        array("Strawberry", 10),
        array("Chocolate", 20),
        array("Vanilla", 30)
    );
    $weekday = date('N');
    $week = date('W');
    $hour = date('G');

    if ($weekday == 4) {
        echo "Hi";
    }
?>
<?php
    $today = date("l F j, Y");
        if ($weekday % 2 == 1 && $week % 2 == 1 && $hour >= 14 && $hour < 17){              
            echo "Congratulations! You get a 5% discount, and your wares will be delivered tomorrow!";  
        }   
    PRINT "$today";
?>
<table border="1">
        <tr>
            <th>Taste</th>
            <th>Price</th>
            <th>Discount</th>
            <th>Amount</th>
        </tr>
    <?php
        for($i = 0; $i<count($donuts); $i++) {
        echo "<tr>";
        echo "<td>".$donuts[$i][0]."</td>"; 
        if( $weekday == 1){
            echo"<td>".getPricePercent($donuts[$i][1], .5)." kr</td>";
            }           
            if( $weekday == 3){
                echo"<td>".getPricePercent($donuts[$i][1], 1.1)." kr</td>";     
            }           
            $pris = $donuts[$i][1];
                if ($weekday == 5 && $pris > 20){
                    echo"<td>".($pris-1)." kr</td>";
                }           
                else { echo"<td>".getPrice($donuts[$i][1], .9)." kr</td>";}
    ?>
            <td><input type="number" name="donuts-<?php echo $i; ?>" /></td>
            <?php
                echo "</tr>";
        }
            ?>
</table>
<?php
    function getPrice($price, $percent) {
        return ($price);
    }
    function getPricePercent($price, $percent){
        return ($price * $percent); 
    }   
?>

If you want to concat the strings, you can achieve it by using something like this:

echo "Price" . $price . "Amount" . $amount;

I dont exactly understand what you are trying to print in price and discount section. You can add getDiscount function to make your code clean.

function getDiscount($weekday, $price){
    if($weekday == 1){
        return .5;
    } else if($weekday == 3){
        return 1.1;
    } else if($weekday == 5 && $price > 20){
        return $price-1;
    }
}

Then you can do that,

<table border="1">
        <tr>
            <th>Taste</th>
            <th>Price</th>
            <th>Discount</th>
            <th>Amount</th>
        </tr>
        <?php
        for($i = 0; $i<count($donuts); $i++) {
            echo "<tr>";
            echo "<td>".$donuts[$i][0]."</td>";
            echo"<td>".getPricePercent($donuts[$i][1], getDiscount($weekday,$donuts[$i][1]))." kr</td>";
            echo"<td>".getPrice($donuts[$i][1], getDiscount($weekday,$donuts[$i][1]))." kr</td>";
            ?>
            <td><input type="number" name="donuts-<?php echo $i; ?>" /></td>
            <?php
            echo "</tr>";
        }
        ?>
    </table>

Still, i dont understand, are you trying to dynamically update values of price depending on the amount ?