-2

I have a boolean in php. When I do something like :

  sprintf('isTrue=%s', isTrue)
    Here isTrue is boolean

I get something like isTrue=1 or isTrue=. Is there simple way to get isTrue=True or isTrue=False

danish sodhi
  • 1,793
  • 4
  • 21
  • 31

3 Answers3

5
sprintf('isTrue=%s', isTrue ? "True" : "False");
Peter Featherstone
  • 7,835
  • 4
  • 32
  • 64
Ethan
  • 301
  • 1
  • 9
1

You could use a little utility function like this perhaps

function _bool($b){
    return $b ? 'True' : 'False';
}

echo _bool( $var );
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
1
echo $isTrue ? 'true' : 'false';

If it isTrue is a function that return bool value:

echo isTrue() ? 'true' : 'false';

To get with data type:

$isTrue = false;
var_dump($isTrue);
Blasanka
  • 21,001
  • 12
  • 102
  • 104