Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何传递值并限制循环_Php - Fatal编程技术网

Php 如何传递值并限制循环

Php 如何传递值并限制循环,php,Php,如何将循环限制为仅五次迭代 当我执行第一个循环时,我希望$specials\u index->fields['products\u name']值为。二是,三是,四是,五是, 如何实现这一点?以下是将循环限制为5次迭代的代码: <?php $col = 0; if ($num_products_count > 0) { while (!$specials_index->EOF) { $list_box_contents[$row][$col] ='

如何将循环限制为仅五次迭代

当我执行第一个循环时,我希望$specials\u index->fields['products\u name']值为。二是,三是,四是,五是,


如何实现这一点?

以下是将循环限制为5次迭代的代码:

<?php

  $col = 0;
  if ($num_products_count > 0) {
    while (!$specials_index->EOF) {
      $list_box_contents[$row][$col] ='<a>'.$specials_index->fields['products_name']. '</a>';
      $col ++;
    }
  }

?>
这很简单

$specials_index->fields['products_name'] = '<img src="'.$i.'">';

哇!你真的不努力!
$specials_index->fields['products_name'] = '<img src="'.$i.'">';
  $col = 0;
  if ($num_products_count > 0) {
    while (!$specials_index->EOF) {
      $list_box_contents[$row][$col] ='<a>'.$specials_index->fields['products_name']. '<img src="'.$col+1.'"></a>';
      $col ++;
      if ($col = 5) { break; }
    }
  }