![]() ![]() If you use three of them, PHP will compare both value and type and only if both of them match, the expression is true. The difference is if you use two equal signs, PHP will only look to see if the values are identical. PHP actually takes it one step further, introducing the triple equal sign. Had we only used one equal sign, 42 would be assigned to $number, and no comparison would have been made. So, in this case, we use two equal signs to compare the two items: $number and 42. Two equal signs are a comparison operator, that is, it's used to compare two values. If you change the number in the first line to something else, you will see that the echo line is not executed.Īs you can see, we are using two equal signs after each other - why is that? In PHP, and in many other programming languages, a single equal sign is an assignment operator. The next line of code will only be executed if the condition evaluates to true. In the next line, we use the if statement to check if the number is what we expect. We declare a variable called number and assign the value 42 to it. ![]() ![]() If not, here are some examples to get you started. If you have already used another programming language, chances are that you can use the PHP if statement straight away, since it looks pretty much the same as in other programming languages. Being able to set up conditional blocks of code is a fundamental principal of writing software. One of the single most important statements in every programming language is the "if" statement. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |