Stop running a certain php snippet

1

I need to stop the operation of a particular piece of code. The exit, as far as die, stops the whole foreach code block.

I just need to stop inside the if, but keep running the foreach, then go back to those ifs, but do not run the first if

for example

  foreach ($stmt->fetchAll() as $item => $value){

            $this->return = '
                <div class="form-group">
                    <div class="col-lg-12">
                       ';
                        if($value->nome_categoria === 'USERS') {
                            $this->return .= 'USERS';
                            $this->achouUsers = true;
                            while (!$this->achouUsers){
                                continue;
                            }

                        }

                        if($value->nome_categoria === "OPTIONS"){
                            $this->return .= 'OPTIONS';
                            $this->achouUsers = true;
                            while (!$this->achouOptions){
                                continue;
                            }
                        }


                        if( $value->nome_categoria === "MFP E CONNECTOR" ){
                            $this->return .= 'MFP E CONNECTOR';
                            while (!$this->achouMDF){
                                continue;
                            }
                        }
                    $this->return .= '
                    </div>
                    <div class="col-lg-12">                            
                         <div class="col-lg-10">
                              <input type="radio" name="inputUsuarios">
                              '.utf8_encode($value->nome_item).'
                              '.(utf8_encode($value->nome_item) === 'Até' ? '<input type="text" > usuários <button  class=" btn btn-warning"><i class="fa fa-calculator"></i> </button>' : '').'

                         </div>
                         <div class="col-lg-2 text-right">
                              '.number_format($value->valor_item,2,',','.').'
                         </div>
                    </div>                           

                </div>

                ';

            echo $this->return;
        }

ran the USERS if only once. from that run everything, and continue running, but testing instead of USERS, but OPTIONS

EDITION 1

The expected result was something like

USERS

OPTIONS

Displayingthecategoryonlyonce,theUSERSontopofthatimage,theOPTIONSontopofthatimage,andsoon.Hepullingfromthebankbutonlyappearingonce.

Withthiscodemyreturnissomethinglike

    
asked by anonymous 17.07.2017 / 15:45

1 answer

1

Where you do it:

if($value->nome_categoria === 'USERS') {
    $this->return .= 'USERS';
    $this->achouUsers = true;
    while (!$this->achouUsers){
        continue;
    }

}

if($value->nome_categoria === "OPTIONS"){
    $this->return .= 'OPTIONS';
    $this->achouUsers = true;
    while (!$this->achouOptions){
        continue;
    }
}

if( $value->nome_categoria === "MFP E CONNECTOR" ){
    $this->return .= 'MFP E CONNECTOR';
    while (!$this->achouMDF){
        continue;
    }
}

As I said, this code does not make much sense. Because all options are generated from the same loop repetition and you want the title to be displayed each time you change the category, you can create an extra control variable that retains the current category name, and when it is different, display again the title. Something like:

if ($value->nome_categoria != $categoriaAtual) {
    $this->return .= $value->nome_categoria;
    $categoriaAtual = $value->nome_categoria;
}

Remember that before foreach you need to start the variable:

$categoriaAtual = "";
    
17.07.2017 / 16:17