Sutrumpintas if if-else konstrukcijoje

Tarkime, pavyzdžiui, mes norime sužinoti, ar kintamasis $test yra lygus reikšmei true. Šiuo atveju if konstrukciją galima užrašyti taip:

php<?php
  $test = true;
  
  if ($test == true) {
    echo '+++';
  } else {
    echo '---';
  }
?>

Programuojant tokie patikrinimai reikalingi labai dažnai, todėl jiems yra sukurtas elegantiškesnis sutrumpintas variantas: vietoj if ($test == true) galima parašyti tiesiog if ($test).

Perrašykime mūsų kodą sutrumpinta forma:

php<?php
  $test = true;
  
  if ($test) { // ekvivalentu if ($test == true)
    echo '+++';
  } else {
    echo '---';
  }
?>

Tarkime dabar mes tikriname, ar kintamasis $test nėra lygus true:

php<?php
  $test = true;
  
  if ($test != true) {
    echo '+++';
  } else {
    echo '---';
  }
?>

Šiuo atveju sutrumpintas sintaksė atrodys taip:

php<?php
  $test = true;
  
  if (!$test) { // naudojame loginį NE
    echo '+++';
  } else {
    echo '---';
  }
?>

Panašus sutrumpinimas egzistuoja ir patikrinimui į false. Tarkime, duotas toks kodas:

php<?php
  $test = true;
  
  if ($test == false) {
    echo '+++';
  } else {
    echo '---';
  }
?>

Sąlyga $test == false iš tikrųjų yra tas pats, kas $test != true:

php<?php
  $test = true;
  
  if ($test != true) { // ekvivalentu if ($test == false)
    echo '+++';
  } else {
    echo '---';
  }
?>

O tokią sąlygą mes jau išmokome sutrumpinti ankstesniame pavyzdyje. Sutrumpinkime:

php<?php
  $test = true;
  
  if (!$test) {
    echo '+++';
  } else {
    echo '---';
  }
?>
Задание 1

Perrašykite šį kodą naudodami sutrumpintą palyginimą:

php<?php
  $test = true;
  
  if ($test == true) {
    echo '+++';
  } else {
    echo '---';
  }
?>
Задание 2

Perrašykite šį kodą naudodami sutrumpintą palyginimą:

php<?php
  $test = true;
  
  if ($test == false) {
    echo '+++';
  } else {
    echo '---';
  }
?>
Задание 3

Perrašykite šį kodą naudodami sutrumpintą palyginimą:

php<?php
  $test = true;
  
  if ($test != true) {
    echo '+++';
  } else {
    echo '---';
  }
?>
Задание 4

Perrašykite šį kodą naudodami sutrumpintą palyginimą:

php<?php
  $test = true;
  
  if ($test != false) {
    echo '+++';
  } else {
    echo '---';
  }
?>