Jump to content

Code Help


Recommended Posts

<?php

    $bool = true;

    print "Bool is set to $bool\n";

    $bool = false;

    print "Bool is set to ";

    print (int)$bool;

?>

I was wondering about one thing in this script.

what is the (int) mean.  I know bool is just a variable create which is short fo boolean, and it's set to the booleon true, here is the website it came off of the exact page actually I was just wondering if int was a preset something in php or something he named himself or what, and what it does.

[a href=\"http://www.hudzilla.org/phpbook/read.php/3_3_0\" target=\"_blank\"]http://www.hudzilla.org/phpbook/read.php/3_3_0[/a]

Link to comment
Share on other sites

The (int) is a typecast; it tells the interpretor to treat the variable as the data type within the parentheses, in this case as an integer.

 

If you remove the typecast, the script will output:

Bool is set to true
Bool is set to

 

This is because when you echo false, nothing is echoed.  By using the typecast, the output becomes:

Bool is set to true
Bool is set to 0

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.