Question

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
}
Was it helpful?

Solution 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
}

OTHER TIPS

Why don't you simply do this:

if($key === 0) {
    // add your code
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top