PHP'de empty Komutu
Genellikle betiklerde bir değişkenin boş olup olmadığını
kontrol etme ihtiyacı doğar. PHP'de bir değişken
0, '',
'0', false veya null değerine eşitse boş kabul edilir.
Boş olma kontrolü empty komutu kullanılarak
yapılır:
<?php
$test = '';
if (empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Ancak daha sık olarak, bir değişkenin boş olmadığını kontrol etme görevi ortaya çıkar. Koşulumuzu tersine çevirelim:
<?php
$test = '';
if (!empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = 0;
if (empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = -1;
if (empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = '';
if (!empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = -1;
if (empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = '0';
if (!empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = -1;
if (!empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = null;
if (empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = false;
if (!empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = true;
if (!empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = 'false';
if (!empty($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = 'null';
if (!empty($test)) {
echo '+++';
} else {
echo '---';
}
?>