PHP'de Dizi Elemanının Varlığını Kontrol Etme
isset ile bir dizi elemanının varlığını
kontrol edebilirsiniz:
<?php
$arr = ['a', 'b', 'c'];
if (isset($arr[5])) {
echo $arr[5];
} else {
echo 'element does not exist';
}
?>
Var olmayan bir dizinin elemanı da kontrol edilebilir:
<?php
if (isset($arr[5])) {
echo $arr[5];
} else {
echo 'array or element does not exist';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = 0;
if (isset($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = null;
if (!isset($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = null;
if (isset($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
if (!isset($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = '';
if (isset($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
if (!isset($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$test = false;
if (isset($test)) {
echo '+++';
} else {
echo '---';
}
?>
Kodu çalıştırmadan, ekrana ne yazdırılacağını belirleyin:
<?php
$arr = [1, 2, 3, 4, 5];
if (isset($arr[])) {
echo '+++';
} else {
echo '---';
}
?>