kohana3.3:执行find_all()而{第一元素的标准}并在此后回显其余元素

时间:2012-12-10 18:41:35

标签: php foreach while-loop kohana kohana-3

我需要这个棘手的事情:以随机方式选择10个项目,一个项目用于真/假标准,其余九个项目用于回应:

$unique_items=array('bike', 'doll', 'carpet', 'postcard');

do {
   $items=ORM::factory('Shop')
     ->order_by(DB::expr('Rand()'))//this way I take 10 random rows from the table
     ->limit(10)
     ->find_all();
}while (in_array(first_item_from_ten_rows->name, $unique_items));

foreach ($items as $item){
   echo $item->name;//display 2nd, 3rd, ..., 10th items, without the first one
}

我在这里使用的php框架是Kohana3.3

1 个答案:

答案 0 :(得分:0)

我不确定这是否是你需要做的:

$first = TRUE
foreach ($items as $item) 
{
   if ($first)
   {
      $first = FALSE;
   }
   else
   {
      echo $item->name;
   }
}