一种从当前文件中加载 PHP require_once 数据的方法

是否可以在 require_once 中添加数据?我不能很好地解释它,所以我只是展示它。


因此,当我加载索引页时,它会加载一个内部包含数据的结构。


// Index

<?php

require_once('/structure.php');

// THIS DATA NEEDS TO SEND TO STRUCTURE, INCLUDING PHP

if (2 > 1)

{

  ?>

  <td>Jill</td>

  <?php

}

?>

这是结构


// '/structure.php'

<table>

 <?php 

 // HERE THE DATA NEED TO LOAD

 ?>

</table>

所以它最终在索引中看起来像这样。


// Index

<table>

 if (2 > 1)

 {

   ?>

   <td>Jill</td>

   <?php

 }

 ?>

</table>


慕慕森
浏览 70回答 2
2回答

翻翻过去那场雪

这似乎是构建代码的糟糕方式。话虽如此,这是我能想到的最不糟糕的方法。索引.php<?php$requireVersion = '2';require_once('/structure.php');结构.php<table>&nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; $requireFile = '/structure_include' . $requireVersion . '.php';&nbsp; &nbsp; &nbsp; if ( file_exists($requireFile) ) {&nbsp; &nbsp; &nbsp; &nbsp; require_once($requireFile);&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; ?></table>structure_include1.php<?phpif (1 > 2){&nbsp; echo '<td>Jack</td>';}structure_include2.php<?phpif (2 > 1){&nbsp; echo '<td>Jill</td>';}

狐的传说

从技术上讲,需要一个必需的文件是可能的。但这将是一个无限循环。我可以建议:索引.php<table><?php&nbsp;require_once('structure.php');if(2 > 1){&nbsp;if(isset($_SESSION['temp_markup']){&nbsp;echo $_SESSION['temp_markup'];}}?></table>结构.php<?phpsession_start();$html = '<td>Jill</td>';//add session or some storage manner$_SESSION['temp_markup'] = $html;?>那是我基于这个相当令人困惑的问题的想法。
打开App,查看更多内容
随时随地看视频慕课网APP