If-else konstruksiyasida qisqartirilgan if

Faraz qilaylik, masalan, $test o'zgaruvchisi true qiymatiga teng yoki yo'qligini bilmoqchimiz. Bunday holda if konstruksiyasini quyidagicha yozishimiz mumkin:

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

Dasturlashda bunday tekshiruvlar juda ko'p kerak bo'ladi, shuning uchun ular uchun yanada chiroyli qisqartirilgan shakl mavjud: if ($test == true) o'rniga shunchaki if ($test) deb yozish mumkin.

Keling, kodimizni qisqartirilgan shaklda qayta yozamiz:

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

Endi faraz qilaylik, $test o'zgaruvchisi true ga teng *emasligini* tekshirmoqchimiz:

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

Bunday holda qisqartirilgan sintaksis quyidagicha bo'ladi:

php<?php
  $test = true;
  
  if (!$test) { // mantiqiy NOT (YO'Q) dan foydalanamiz
    echo '+++';
  } else {
    echo '---';
  }
?>

false ni tekshirish uchun ham shunga o'xshash qisqartirma mavjud. Quyidagi kod berilgan deb faraz qilaylik:

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

$test == false sharti aslida $test != true bilan bir xil:

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

Xo'sh, bunday shartni biz oldingi misolda qisqartirishni o'rgangan edik. Qisqartiramiz:

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

Quyidagi kodni qisqartirilgan taqqoslashdan foydalangan holda qayta yozing:

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

Quyidagi kodni qisqartirilgan taqqoslashdan foydalangan holda qayta yozing:

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

Quyidagi kodni qisqartirilgan taqqoslashdan foydalangan holda qayta yozing:

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

Quyidagi kodni qisqartirilgan taqqoslashdan foydalangan holda qayta yozing:

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