IF with 2 distinct variables for various scenarios

0

I'm trying to make a condition in php this way:

$Telefone = "";
$Celular = "";

Where:

  • If both empty shows echo sem Telefone e nem Celular
  • If variable Phone = 222-2222% with%
  • If instead echo Telefone: 2222-2222
  • If both are not empty it will be echo Celular: 9999-99999

I could not mount.

<?php   

$Telefone= "Telefone";
$Celular= "";

if (empty($Telefome) and empty($Celular)) {
    echo "Tel=Vazio e Cel=Vazio";
}
else
{
    if (empty($Telefome) and empty($Celular)) {
        echo "so". " " . $Telefone;
    }
    else
    {
        echo $Celular. "e". $Telefone;
    }
}
?>
    
asked by anonymous 20.12.2018 / 02:05

2 answers

0
<?php
if($Telefone == "" && $Celular == ""):
  echo "Sem contato";
elseif($Telefone != "" && $Celular != ""):
    echo "Telefone:".$Telefone."Celular: ".$Celular;
elseif($Telefone == ""):
    echo "Celular: ".$Celular;
else:
    echo "Telefone: ".$Telefone;
endif;
?>
    
20.12.2018 / 02:20
0

A form using if , else if and else :

<?
if(empty($Telefone) && empty($Celular)){

   echo "sem Telefone e nem Celular";

}else if(!empty($Telefone) && empty($Celular)){

   echo "Telefone: ". $Telefone;

}else if(empty($Telefone) && !empty($Celular)){

   echo "Celular: ". $Celular;

}else{

   echo "Telefone: ". $Telefone . " e Celular: ". $Celular;

}
?> 
    
20.12.2018 / 03:20