我如何在Codeigniter中使用foreach复制某个数字

时间:2019-03-10 23:39:38

标签: php codeigniter loops foreach

代码:

<?php foreach($posts as $post) {

echo $post['name'] 
};
?>

结果:1​​00值 我只想打印10个值?

1 个答案:

答案 0 :(得分:0)

尝试这样

foreach($posts as $key => $post) {
  echo $post['name']; 

  //It will execute only ten times
  if($key == 9){
     break;
  }
}