1 00:00:00,900 --> 00:00:05,870 An operator is something that takes 1 or more values and yields another value. 2 00:00:05,870 --> 00:00:08,970 I've shown you several different operators so far. 3 00:00:08,970 --> 00:00:14,500 The assignment operator uses the equal sign to put a value into a variable. 4 00:00:14,500 --> 00:00:19,940 The arithmetic operators let you add, subtract, divide, and multiply numbers. 5 00:00:19,940 --> 00:00:23,770 And the concatenation operators let you create a new string 6 00:00:23,770 --> 00:00:26,680 by combining several strings together. 7 00:00:26,680 --> 00:00:31,340 Next we'll be looking at comparison operators for equality. 8 00:00:31,340 --> 00:00:34,590 Comparison operators do exactly what they sound like. 9 00:00:34,590 --> 00:00:38,170 They allow us to compare values and yield the result. 10 00:00:38,170 --> 00:00:40,300 There are quite a few comparison operators, and 11 00:00:40,300 --> 00:00:42,540 we'll cover them all in a later course. 12 00:00:42,540 --> 00:00:44,980 I have included more information in the teacher's notes, 13 00:00:44,980 --> 00:00:46,970 if you want to learn more now. 14 00:00:46,970 --> 00:00:51,620 For this course, we'll be looking at equal and identical comparisons. 15 00:00:51,620 --> 00:00:57,341 Equal compares only the value, while identical compares the value and the type. 16 00:00:57,341 --> 00:01:01,841 We've looked at the number of different variable types in PHP including 17 00:01:01,841 --> 00:01:04,360 integers, floats, strings and booleans. 18 00:01:04,360 --> 00:01:08,820 PHP is called a weakly or loosely typed language. 19 00:01:08,820 --> 00:01:13,500 This means that, generally, you don't need to specify the type you'll be using. 20 00:01:13,500 --> 00:01:15,960 PHP will automatically assign the type for 21 00:01:15,960 --> 00:01:19,240 you based on the value inside the variable. 22 00:01:19,240 --> 00:01:22,110 This also means that PHP will attempt 23 00:01:22,110 --> 00:01:27,200 to juggle the types to work within the situation in which they're being used. 24 00:01:27,200 --> 00:01:30,090 We saw this when working with number variables. 25 00:01:30,090 --> 00:01:33,620 When you were using the plus sign to add two variables 26 00:01:33,620 --> 00:01:38,400 PHP assumes that those values should be evaluated as numbers. 27 00:01:38,400 --> 00:01:41,130 Type juggling can be helpful when accepting data 28 00:01:41,130 --> 00:01:45,730 from sources beyond your control like user data from a web form. 29 00:01:45,730 --> 00:01:49,970 Values submitted from an online form are collected as a string, but 30 00:01:49,970 --> 00:01:52,950 they can be used in a calculation because of Type Juggling. 31 00:01:54,380 --> 00:01:59,166 Let's comment out 32 00:01:59,166 --> 00:02:04,553 these output lines. 33 00:02:04,553 --> 00:02:06,295 Then let's start with something simple. 34 00:02:06,295 --> 00:02:14,421 We'll add var_dump(1 + "2"). 35 00:02:14,421 --> 00:02:16,824 Now let's run our script. 36 00:02:16,824 --> 00:02:20,561 Since we're using an addition operator, 37 00:02:20,561 --> 00:02:26,163 when we run our program PHP juggles the string 2 to an integer and 38 00:02:26,163 --> 00:02:31,382 adds 1 + 2, which gives us the integer 3 as the result. 39 00:02:31,382 --> 00:02:34,161 So now let's take a look at the comparison operator. 40 00:02:34,161 --> 00:02:39,941 We'll start by creating two variables, 41 00:02:39,941 --> 00:02:43,083 a = 10 and b = '10'. 42 00:02:43,083 --> 00:02:46,129 Then we can compare these variables as equal and 43 00:02:46,129 --> 00:02:48,879 use our var_dump to display the results. 44 00:02:57,421 --> 00:02:59,001 When we run the script, 45 00:02:59,001 --> 00:03:03,430 we see that the evaluation is true because both values equal 10. 46 00:03:03,430 --> 00:03:08,330 If we want to compare if these variables are identical, meaning that 47 00:03:08,330 --> 00:03:13,577 the value is the same and also the type is the same we use the triple equals. 48 00:03:20,227 --> 00:03:24,909 When we run the script now, we see that the evaluation is false, 49 00:03:24,909 --> 00:03:27,610 because a and b are not the same type. 50 00:03:28,840 --> 00:03:31,528 We can also use these to compare strings. 51 00:03:31,528 --> 00:03:36,253 We'll var_dump again, and 52 00:03:36,253 --> 00:03:41,545 then we'll compare string_one 53 00:03:41,545 --> 00:03:46,837 to be equal to learning to display 54 00:03:46,837 --> 00:03:51,190 Hello Alena to the screen. 55 00:03:54,900 --> 00:03:58,710 Let's uncomment this line to echo out our string, so 56 00:03:58,710 --> 00:04:00,110 we can see what that looks like. 57 00:04:03,230 --> 00:04:03,730 Great. 58 00:04:05,410 --> 00:04:11,230 Well, let's also comment about these //var_dumps. 59 00:04:11,230 --> 00:04:11,860 There we go. 60 00:04:11,860 --> 00:04:13,850 That should make our output a little easier to read. 61 00:04:16,280 --> 00:04:19,640 Our result of string_one isn't exactly the same, 62 00:04:19,640 --> 00:04:25,080 because we have I am in front, and we also have a new line. 63 00:04:25,080 --> 00:04:27,990 So the var_dump evaluates to the boolean false. 64 00:04:27,990 --> 00:04:32,331 Let's update the string_one value and remove the new line and 65 00:04:32,331 --> 00:04:34,985 prepend string using our comments. 66 00:04:37,843 --> 00:04:39,750 Not this or this. 67 00:04:42,470 --> 00:04:43,570 Now let's run our script again. 68 00:04:44,800 --> 00:04:47,080 Great, now our var_dump evaluates to true. 69 00:04:47,080 --> 00:04:51,890 Even though string_one uses the name variable, the values are the same.