PHP include file multiple times in one page

前端 未结 1 1528
我在风中等你
我在风中等你 2020-12-10 19:09

I have a php-file called kal_test.php which gives a value to the variable $vbl. This variable is needed in the file called kal_generator.php<

相关标签:
1条回答
  • 2020-12-10 19:15

    You're likely defining a function or class in kal_generator.php. PHP aborts when you try to redefine such a function or class. Consider putting your code in a function, include that function once and then run the function instead of including a file.

    kal_test.php

    <?php
    require_once 'kal_generator.php';
    kal_generator("14/09/2011");
    kal_generator("21/09/2011");
    ?>
    

    kal_generator.php

    <?php
    function kal_generator($vbl) {
        /**
         * Here, you should be creating $output
         */
        echo <<EOF
    <table>
      <tr><th>bla</th><th>blabla</th></tr>
    
    EOF;
        foreach ($output as $v1) {
            echo "<tr>";
            foreach ($v1 as $v2) {
                echo "<td>$v2</td>";
            }
            echo "</tr>\n";
        }
    
        echo "</table>\n";
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题