Вопрос

I would like below condition.

if key = 0 then below should work.

$key = 0;
if($key){
  //code should execute
}

But if the key is blank then it should not work.

$key ="";
if($key){
  //code should not execute
}
Это было полезно?

Решение 2

This will work will strings / ints, but you will see a warning if you try to use this code when $key is an array.

if(strlen($key) > 0) {
  // execute
}

Другие советы

Why don't you simply do this:

if($key === 0) {
    // add your code
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top