如何在与函数相同的php文件中使用include_一次

如何在与函数相同的php文件中使用include_一次,php,Php,我试图使用include_一次,因为我得到了致命错误cannot redeclare function()错误,但我不知道如何使用它 call_trendy()函数的灵感来自以下著名链接: 但它似乎是用来调用文件外的函数的,我的问题不是这样的 <?php function trendy($Name, $Price, $percent, $trend){ //used to create the winners and losers table $link = "http

我试图使用include_一次,因为我得到了致命错误cannot redeclare function()错误,但我不知道如何使用它

call_trendy()函数的灵感来自以下著名链接: 但它似乎是用来调用文件外的函数的,我的问题不是这样的

<?php

function trendy($Name, $Price, $percent, $trend){
//used to create the winners and losers table
    $link = "https://signal-invest.com/tick/?ticker=";
    echo "<tr>
    <td><a href=\"$link$Name\" style='color:#616161;' >$Name</a></td>
    <td>$Price</td><td style='color: "; echo ($percent < 0 ? '#FF0000' : '#4ca64c'); echo ";'>$percent%</td><td>$trend</td></tr>";}

if (file_exists($trendy)) {
  include_once($trendy);
}

$query_uptrend= $con -> prepare(my query, which is irrelevant);
$query_uptrend->execute();
$results_query_uptrend = $query_uptrend->get_result();

echo "<body>";

?>
<div class="table_container_frontpage">
                                <div class="table_latest" style="box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);">
                                    <table style="border-radius: 0.50rem;">
                                         <tr>
                                                <th>NAME</th>
                                                <th>PRICE TODAY</th>
                                                <th>CHANGE</th>
                                                <th>TREND DAYS IN A ROW</th>
                                         </tr>
                                         <?php
                                                foreach ($results_query_uptrend as $res){
                                                    $name = $res["Name"];
                                                    $Price = number_format((float)$res['Price'], 2, '.', '');
                                                    $percent_diff = number_format((float)$res['PercentDiff'], 2, '.', '');
                                                    $trend = $res["uptrend"];
                                                    echo trendy($name, $Price, $percent_diff, $trend);
                                                    }
                                                ?>
                                    </table>
                                </div>
                            </div>
<?php

?>

阅读
上的文章是否会有帮助?这是否回答了您的问题?你刚才问这个问题几乎就在刚才。为什么对这些论坛发垃圾邮件?什么是
include_once$obj=trendy($Name,$Price,$percent,$trend)应该怎么做
include_once
是包含一个文件,您的代码似乎到处都是。您的
trendy
函数打印一些HTML,但随后调用
echo trendy()
就好像它返回了一些东西一样。然后,您尝试包含函数的结果(它是空的,因为它不返回),这毫无意义。您需要确定该函数实际被重新声明的点,这不能从您发布的代码中得出结论。
if (file_exists($trendy)) {
  include_once($trendy);
}