首页 > 解决方案 > PHP 产生构建 html 代码.. 有可能吗?

问题描述

不是很懂yield PHP....网上所有的例子都不是有用的例子。

例如,在我的网络应用程序中,实际上,通过我使用的函数创建结果的 GUI:

<?php

function get_results_from_database($id) {

 //connect to database

 //omitted

 return $array_results; //it is an array

}

现在我的html页面是这样的:

<html>
<body>
<div>
<?php

 $res = get_results_from_database(5); // for example it returns 1.000 rows
 foreach ( $res as $index => $row ) {
   echo '<p>' . $row['Name'] . '</p>';
 }

 echo '<p>TOTAL ROWS: ' . count($res) . '</p>';

?>
</div>

像这样的代码可以用 yield 方法转换吗?我不明白它的含义....如果产量用于异步请求,则将其用于创建图形 HTML 页面毫无意义...或者我错过了一些东西?

我在哪里可以找到收益方法的有用示例?

标签: phpyield

解决方案


推荐阅读