Can I use many IF’s in PHP?

Asked

Viewed 143 times

-1

I’m doing a project where I need to create a csv from a mysql table, to create the csv I need to follow the norms of type documents, when I went to write the code I realized that it would possess many if’s for the adaptation of the bank, whether it is due to the amount of fields present in csv, I was wondering if it is a problem to fill the while that fulfills the csv of conditions or there is an easier way to do this.inserir a descrição da imagem aqui

Example of code start

  • 1

    already processes this in mysql. uses the CASE command for this

  • I think it’s okay. Because, by your code, you don’t need to use as many if’s like that. Just think that your second and third IF’s you could leave so if($Row['RG_ORGAO'] = "SSPSP"){$c = "TEST";} Else if {$Row['RG_ORGAO'])}{$c = "empty";}. You could also use a ELSE (if applicable) right after, in case your IF and ELSE IF conditions are not met.

1 answer

0

No problem using several ifs

However, in this particular case of yours, I also have the option of using a switch case, you can also choose to use operador tenário

Example:

How would it be in IF

  $z = $row['sexo']; 
  if ($z == 'M')
  {
    $z = '1';
  }
  else
  {
    $z = "2";
  }   
  echo $z;

How it would be in Tennis Operator

$z = $row['sexo']; 
$z = $z == 'M' ? "2" : "1";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.