-4

PHP echo no text if $name is not filled in or == 0 else echo $name

For example here's what I have:

<?php
if ($name == 0)
{ 
echo $name;
}
else
{
echo "Nothing here.";
?>
user1641508
  • 325
  • 1
  • 3
  • 4

4 Answers4

1
<?php
if (empty($name))
{ 
  echo "Nothing here.";
}
else
{
  echo $name; 
}
?>

empty() -> Gives True if ist emty!

j_s_stack
  • 667
  • 1
  • 5
  • 18
0

check if this is working:

<?php
if ($name == 0)
    {echo "Nothing here";}
else
    {echo $name;}
?>
Hemang
  • 26,840
  • 19
  • 119
  • 186
0

See this php is null or empty?

The code should be

<?php
if ($name === NULL) {
    echo "Nothing here.";
} else {
    echo $name;
}
?>
Community
  • 1
  • 1
t2k269
  • 1
0

Why not try

<?php
echo empty($name)? 'Nothing here.' : $name;
?>

empty() return true means $name is null, 0 or not defined.

Richer
  • 116
  • 3