10/4/2023 0 Comments Php if else ifThis stops PHP from trying to execute both the true and false actions. Therefore 1 = 1 is true, and 1 = 2 is false.ĭid you notice that if statements use the code blocks I mentioned earlier? The code to be executed if the statement is true is in its own block (remember a block starts with ), and the code to be executed otherwise is in an else block. We will be looking at the complete list later, but first I want to mention one key check: =, or two equals signs put together. You have a vast array of ways to check statements, of which we have just looked at = (greater than or equal to). In this situation, if any of the conditions being checked in an if statement is true, the whole statement is considered true. The double ampersand, &, means that both statements must be true if the print "You're in the prime of your life\n" code is to be executed - if either one of the statements is not true for some reason, "You're not in the prime of your life" is printed out instead.Īs well as &, there is also || (the pipe symbol printed twice) which means "OR". PHP evaluates if statements left to right, meaning that it first checks whether $Age is greater or equal to 18, then checks whether $Age is less than 50. This condition can be anything you choose, and you can combine conditions together to make for actions that are more complicated. PHP allows you to choose what action to take based upon the result of a condition.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |