1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 5.00 out of 5)

PHP7 DATA TYPES INTEGERS FLOATS STRINGS BOOLEAN LESSON 10

Booleans in PHP7

A Boolean value will return TRUE or FALSE. If an integer is zero 0 it is considered FALSE in PHP7. If a string has nothing in it then it is considered FALSE in PHP7. Negative numbers are considered TRUE to Boolean. Here are some examples.

Integer Boolean False

<?php $var=0; var_dump((bool) $var); ?> 

Result would be: bool(false).

Tip: Click on images to make them larger. If you find anything wrong on this page or need further assistance please comment below or contact me. 🙂

Integer Boolean True

Notice we are using a negative 2 “-2”. Even though it is negative number it is still TRUE to Boolean.

<?php $var=-2; var_dump((bool) $var); ?>

Result would be: bool(true)

Subscribe To My YouTube Channel:

String Boolean False

<?php $var=""; var_dump((bool) $var); ?>

Result would be: bool(false).

How We Would Use Booleans

We use booleans in PHP to see if something is true or false. So if we need to see if a variable has a value or not we can use the var_dump((bool) $var); to see if there is anything in it or not.


booleans-in-php7

Here are the complete files for this lesson. 

 

PHP7 DATA TYPES INTEGERS FLOATS STRINGS BOOLEAN LESSON 10 was last modified: March 9th, 2019 by Maximus Mccullough

Please like, share and subscribe.

Advanced Programming Made Easy

I hope you enjoyed the article. If I was able to help you please consider a tip for the content.

One Time Tip

more tips

Reoccuring Tips

Tips

Cool People Share:
PHP7 DATA TYPES HOW THEY ARE USED

Pages:Previous 1 2 3 4

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.