1 00:00:00,290 --> 00:00:03,970 The first type of variable we're going to look at is an integer. 2 00:00:03,970 --> 00:00:07,415 Integers are whole numbers, such as one through nine, or 3 00:00:07,415 --> 00:00:09,679 negative one through negative nine. 4 00:00:09,679 --> 00:00:14,424 Any of these are considered integers because they aren't numbers that include 5 00:00:14,424 --> 00:00:17,090 decimals or floating point values. 6 00:00:17,090 --> 00:00:20,200 So let's create a couple of integers and see how they work. 7 00:00:21,800 --> 00:00:29,360 Let's create a new file named numbers.php. 8 00:00:29,360 --> 00:00:34,150 Remember, we start a PHP block using the opening and closing php tags. 9 00:00:35,390 --> 00:00:38,020 Now we can create some variables. 10 00:00:38,020 --> 00:00:41,340 The names don't really matter, but I want to keep it readable, so 11 00:00:41,340 --> 00:00:45,780 I'll name the first one num_one. 12 00:00:45,780 --> 00:00:47,800 To store information in this variable, 13 00:00:47,800 --> 00:00:52,690 we use a single equal sign, followed by the value that we want to store. 14 00:00:52,690 --> 00:00:56,220 In this case, I'm going to set it equal to one. 15 00:00:56,220 --> 00:00:59,085 I then end this statement in this line with a semicolon. 16 00:01:00,750 --> 00:01:04,290 If you notice, I'm not putting quotes around the number one. 17 00:01:04,290 --> 00:01:05,895 If I were to put quotes around the one, 18 00:01:05,895 --> 00:01:10,300 PHP would treat this value as a string, not an integer. 19 00:01:10,300 --> 00:01:13,980 I'll show you the difference between strings and integers here in a minute. 20 00:01:13,980 --> 00:01:19,706 But let's create a few more, num_two equals two, 21 00:01:19,706 --> 00:01:23,490 and num_three will equal three. 22 00:01:25,030 --> 00:01:28,630 So now we have three variables, num_one, num_two, and num_three. 23 00:01:28,630 --> 00:01:31,326 Let's display these variables using the echo command. 24 00:01:31,326 --> 00:01:35,201 We’ll echo num_one. 25 00:01:37,210 --> 00:01:38,267 Then we can run this script. 26 00:01:43,391 --> 00:01:46,818 We see that it displays the value, which is one. 27 00:01:46,818 --> 00:01:49,930 Our variable is just a placeholder for the value. 28 00:01:49,930 --> 00:01:51,150 It's just a one. 29 00:01:51,150 --> 00:01:56,080 So what about if we were to just echo, say, one, and not the variable? 30 00:01:56,080 --> 00:01:58,280 Let's also put a one within quotes. 31 00:02:00,450 --> 00:02:01,710 Now let's run our script again. 32 00:02:03,240 --> 00:02:06,615 Now we have three ones, and they all look exactly the same. 33 00:02:06,615 --> 00:02:10,771 So how do we know that something is an integer or something is a string? 34 00:02:10,771 --> 00:02:15,433 PHP includes some functions that we can use to perform many different tasks, 35 00:02:15,433 --> 00:02:18,170 such as looking at the details of a variable. 36 00:02:19,260 --> 00:02:23,670 A function is simply a group of code that performs a function or task. 37 00:02:24,780 --> 00:02:27,840 We'll learn about writing our own functions in a later course, but 38 00:02:27,840 --> 00:02:29,360 we can start using them now. 39 00:02:30,520 --> 00:02:36,412 The first function we'll use is a very handy little function, var_dump. 40 00:02:36,412 --> 00:02:39,940 The var_dump function accepts data within parentheses and 41 00:02:39,940 --> 00:02:42,560 dumps the details about that data. 42 00:02:42,560 --> 00:02:45,045 Instead of echo, let's use var_dump. 43 00:02:46,180 --> 00:02:49,170 We then surround the data we want to use in parentheses. 44 00:02:51,220 --> 00:02:53,102 Let's use the var_dump on all three lines. 45 00:03:03,351 --> 00:03:04,820 Now let's run our script again. 46 00:03:07,310 --> 00:03:11,657 So you'll notice here, the first two types are int, or integer, 47 00:03:11,657 --> 00:03:14,720 with the value of one without quotes. 48 00:03:14,720 --> 00:03:19,530 And the third type is a string with the value of one within quotes. 49 00:03:19,530 --> 00:03:23,230 So now we can tell that there are actually two different types. 50 00:03:23,230 --> 00:03:28,120 At this point, it's not a concern that these two values are different types, 51 00:03:28,120 --> 00:03:31,010 since we're getting the same output either way. 52 00:03:31,010 --> 00:03:35,950 However, as you'll learn later, sometimes, like when performing a math calculation, 53 00:03:35,950 --> 00:03:39,985 the type of information stored in a variable really matters. 54 00:03:39,985 --> 00:03:41,605 So it's good to know that we can test and 55 00:03:41,605 --> 00:03:45,855 find out whether our variable contains an integer or a string. 56 00:03:45,855 --> 00:03:48,355 There are other functions you can use with variables. 57 00:03:48,355 --> 00:03:50,225 So check the teacher's notes for more details. 58 00:03:51,355 --> 00:03:55,895 Let's duplicate the first var_dump line, and do some math calculations. 59 00:03:58,349 --> 00:04:02,359 After num_one, I'm going to use an operator that you see all the time, 60 00:04:02,359 --> 00:04:03,230 the plus sign. 61 00:04:04,868 --> 00:04:06,813 Then I'm going to type num_two. 62 00:04:09,714 --> 00:04:11,150 Now let's run the script again. 63 00:04:13,370 --> 00:04:17,900 We see that the last result is also an integer with a value of three. 64 00:04:17,900 --> 00:04:21,690 One plus two equals three, awesome. 65 00:04:21,690 --> 00:04:23,560 By using the plus operator, or 66 00:04:23,560 --> 00:04:27,300 sum operator, we're able to add two numbers together. 67 00:04:27,300 --> 00:04:31,206 The numbers are integers, and they're stored in variables, 68 00:04:31,206 --> 00:04:34,532 so we can change or retrieve them however we'd like. 69 00:04:34,532 --> 00:04:37,304 Let's do a little bit more here, and say minus. 70 00:04:41,022 --> 00:04:44,750 And now we'll type num_three. 71 00:04:44,750 --> 00:04:46,900 We save the file and run the script again. 72 00:04:48,450 --> 00:04:50,240 That brings us to zero. 73 00:04:50,240 --> 00:04:53,740 One plus two minus three equals zero. 74 00:04:55,390 --> 00:05:00,090 Great job storing, retrieving, and manipulating your first set of data. 75 00:05:00,090 --> 00:05:05,480 That should give you a good understanding of what an integer is and how to use one. 76 00:05:05,480 --> 00:05:07,715 Not all numbers are integers. 77 00:05:07,715 --> 00:05:13,045 Oftentimes, you'll need a floating point value, such as 2.25, to represent 78 00:05:13,045 --> 00:05:18,525 a dollar amount, or other decimal number. Enter our next variable type, floats.