O'zgaruvchining bo'shligini aniqlash

Men $ echimining o'zgaruvchisi bor. Afsuski, quyidagi kod ishlamaydi.

if (!$message) {
    echo 'Nothing here!';
}

var_dump ($ message); Men quyidagi narsani olaman:

string (48) ""

Shunday qilib, u erda bir narsaga o'xshaydi. Har qanday tasodifmi?

Rahmat,

Jon

1
Shunday qilib, magistral uzunligi 48, bo'shmi? $ message ni qanday aniqlaysiz?
qo'shib qo'ydi muallif Qirel, manba

8 javoblar

Use empty()

isset() will return true for empty value

What's the difference between 'isset()' and '!empty()' in PHP?

1
qo'shib qo'ydi

Siz ham foydalanishingiz mumkin:

if($var == "")
{
    echo("nothing here");
}
1
qo'shib qo'ydi
Ishlamadim, men o'zimni yaxshi ko'rganman
qo'shib qo'ydi muallif John Higgins, manba

Ok - I worked it out. I was building the $message variable with a load of MySQL queries and if there we're results displaying the in a table. I had a few tags outside of a if (mysqli_num_rows($result) <> 0) { } clause so they we're being saved in the variable.

Sizning yordamingiz uchun barchangizga rahmat.

0
qo'shib qo'ydi

When you are typing the name of your question, notice, that below many same questions could appear, like in this post, and you will not duplicate it then. For example, first post where you can find many answers: check if variable empty

Va savolingizni yozib olish uchun vaqtni tejaysiz ;-)

0
qo'shib qo'ydi
0
qo'shib qo'ydi
Sizda eng kichik mantiqiy xatolik bor: ! Empty() bo'sh emas ;-)
qo'shib qo'ydi muallif Qirel, manba

Buni ko'ring:

if(!$message || $message == "") {
   echo 'Nothing here!';
}

Siz shuningdek isset ($ message) yoki empty ($ message) dan foydalanishingiz mumkin.

0
qo'shib qo'ydi
Yoki buni if (empty ($ message)) ga soddalashtirishingiz mumkin
qo'shib qo'ydi muallif Qirel, manba

Foydalanishingiz mumkin:

<?php
    is_null($var) //returns true if it's null

    empty($var) //returns true if it's empty

    isset($var) //returns true if it's not null.
?>

https://www.virendrachandak.com/techtalk/php -isset-vs-empty-vs-is_null/

Umid qilamanki yordam berdim!

0
qo'shib qo'ydi

php-da funksiya bo'sh.

 if (empty($message)) {
   echo 'Nothing here!';
 }

Agar kosmik ishlatish funktsiyasi bilan ishora qilsangiz:

 if (empty(trim($message))) {
   echo 'Nothing here!';
 }
0
qo'shib qo'ydi
Ishlamadim, men o'zimni yaxshi ko'rganman
qo'shib qo'ydi muallif John Higgins, manba
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin