Php 从一开始就启动foreach

Php 从一开始就启动foreach,php,foreach,php-5.3,Php,Foreach,Php 5.3,如果条件为false,如何使用新项目启动foreach。 我有以下代码: foreach($a_auctions as $auction){ # get the winner if($auction['for_canada'] == 1 && $isFromCanada){ // another solution to start the foreach with new item (break, exit) ?

如果条件为false,如何使用新项目启动foreach。 我有以下代码:

foreach($a_auctions as $auction){
        # get the winner
        if($auction['for_canada'] == 1 && $isFromCanada){
            // another solution to start the foreach with new item (break, exit) ?
            $this->a_returnData[] = array(
                'winner'       => 'pseudo',
                'title'        => 'title',
                'price'        => 200,
            );
        }else{
            $this->a_returnData[] = array(
                'winner'       => 'pseudo',
                'title'        => 'title',
                'price'        => 200,
          );
        }
    }

在if中,我希望从foreach的新项开始。如果条件不为true,则想法是避免代码重复。我添加了一条评论。

我相信您正在寻找reset()命令!这会将数组指针倒回起始位置,请查看手册!(以下链接)

如果要将另一个元素添加到数组的开头,请使用array_unshift():


请用您想要的输出更新您的问题。请同时更新您的代码,这是错误的@BunkerBoy如果…有可能添加中断或继续?如果条件为false-不要添加
,否则
-branch应该做您需要的事情,我不想重复第一个代码。