How to display 0 and true in "is_int" in php?

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 1925 Views - Last Post: 02 February 2013 - 03:46 AM Rate Topic: -----

#16 Sho Ke  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 110
  • View blog
  • Posts: 250
  • Joined: 13-October 11

Re: How to display 0 and true in "is_int" in php?

Posted 31 January 2013 - 07:45 PM

That's a ternary operator.
Taken from the link above:
// Example usage for: Ternary Operator
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];

// The above is identical to this if/else statement
if (empty($_POST['action'])) {
    $action = 'default';
} else {
    $action = $_POST['action'];
}


Was This Post Helpful? 2
  • +
  • -

#17 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3354
  • View blog
  • Posts: 11,353
  • Joined: 12-December 12

Re: How to display 0 and true in "is_int" in php?

Posted 31 January 2013 - 07:50 PM

'?:' is the ternary operator - the docs. Basically, a shorthand for if..else:

if (is_int($num1)) {
    echo "true";
} else {
    echo 0;
}

Was This Post Helpful? 1
  • +
  • -

#18 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

Re: How to display 0 and true in "is_int" in php?

Posted 31 January 2013 - 08:04 PM

so now i understand!!!! thank you so much for helping me with this thing.. i now understood... i hope God will be bless you always... again thank you so much.... i wish i could be like you... a true programmer...!! :)/>

This post has been edited by Dormilich: 01 February 2013 - 02:30 AM
Reason for edit:: removed quote

Was This Post Helpful? 0
  • +
  • -

#19 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

Re: How to display 0 and true in "is_int" in php?

Posted 31 January 2013 - 08:18 PM

and one more thing i really need to know about..
how to display the value of a variable with a data type null??
it doesnt displays on the browser... :(/>

example:

$num3 = null;
<?php echo $num3; ?>

it doesnt display the null value..

This post has been edited by Dormilich: 01 February 2013 - 02:30 AM
Reason for edit:: removed quote

Was This Post Helpful? 0
  • +
  • -

#20 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2927
  • View blog
  • Posts: 10,114
  • Joined: 08-August 08

Re: How to display 0 and true in "is_int" in php?

Posted 31 January 2013 - 10:20 PM

Null is computer speak for no value, so it can't be displayed. You could do something like:
if($x === null) { echo "null";}


This post has been edited by Dormilich: 02 February 2013 - 04:34 AM
Reason for edit:: made the comparison for NULL exclusively

Was This Post Helpful? 1
  • +
  • -

#21 brerallia  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 146
  • Joined: 21-January 13

Re: How to display 0 and true in "is_int" in php?

Posted 02 February 2013 - 03:46 AM

To all:

Thank you for helping me with this thing.. i am a beginner in php and i appreciate all of your help. thank you so much...!!! :)

To those who help me, dont worry... i will all give you a post up each one... all of you deserve it!!! :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2