PHP7 DATA TYPES INTEGERS FLOATS STRINGS BOOLEAN LESSON 10

Understanding PHP7 data types will help you put things together. There are 8 different data types in PHP. They are all used differently.  We will cover the first 4 types in this lesson and the second half in the next lesson. Here are files from the last lesson. Here are some quick examples of PHP7 data types and how they are used.

PHP7 Data Types

These are the different data types in PHP7.

  1. Integers
  2. Floats
  3. Strings
  4. Boolean
  5. Object – NEXT LESSON
  6. Arrays – NEXT LESSON
  7. NULL – NEXT LESSON
  8. Resource – NEXT LESSON

Integers In PHP7

Integers are whole numbers. They can also include negative numbers. Integers cannot include decimal points. You do not have to include quotes when setting a variable to an integer. Here is an example.

Only cool people share!

<?php $var=2; echo $var; ?>

If you tried to do that with a word you would get an error. Here is an example of the wrong thing to do.

<?php $var=two; echo $var; ?>

Here is an example of the warning you will get.

Warning: Use of undefined constant two – assumed ‘two’ (this will throw an Error in a future version of PHP) in /opt/lampp/htdocs/mywebsite/datatypes.php on line 2
two

Using var_dump To Define A Variable

In PHP7 you can use var_dump($var); to get the type and value of a variable.  So from our example above we can use this.

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

This will return “int(2)“.

How Would You Use Integers in PHP7?

You would use “PHP Integers” when you are doing some kind of math in PHP7. If you are looking for greater than, less than, adding, multiplying or dividing you would want to use integers. Remember that integers are whole numbers not decimals!

use-php-integers-when-doing-math

PHP7 DATA TYPES INTEGERS FLOATS STRINGS BOOLEAN LESSON 10 was last modified: October 29th, 2021 by Maximus Mccullough
PHP7 DATA TYPES HOW THEY ARE USED

Pages: 1 2 3 4 Next

Leave a Reply

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