PHP: If Statement - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21) +---- Thread: PHP: If Statement (/showthread.php?tid=23597) Pages:
1
2
|
PHP: If Statement - BreShiE - 12-05-2011 Introduction: The if statement is necessary for most programming, so it is important in PHP. Imagine that on January 1st you want to print out "Happy New Year!" at the top of your personal web page. With the use of PHP if statements you could have this process automated, months in advance, occuring every year on January 1st. This idea of planning for future events is something you would never have had the opportunity of doing if you had just stuck with HTML. The "Happy New Year" example would be a little difficult for you to do right now, so instead let's start off with the basics of the if statement. The PHP if statement tests to see if a value is true, and if it is, a segment of code will be executed. The If Statement Is Like This: PHP Code: <?php So what we're going to do, is make an if statement to check if someone's name is as it should be. So first of all you're going to want to open your php tags as so: PHP Code: <?php Then you're going to add in a variable: PHP Code: <?php Now we're going to make the statement check if the variable is true. PHP Code: <?php There we go! You've created an If Statement! We can also go further and make it check if it you're not called Jimmy, and then if it's not, echo out something: PHP Code: <?php IF NOT: Along with the If statement, you can tell the page "If NOT Then Do This". EXAMPLE: PHP Code: <?php Next up is the "AND" and "OR" statement, you can do this by placing the actual words or by using "&&" for "AND" and "||" for "OR". OR EXAMPLE: PHP Code: $name = "Jimmy"; AND EXAMPLE: PHP Code: $name = "Jimmy"; RE: PHP: If Statement - BreShiE - 12-07-2011 Added in AND, OR and IF NOT Statements. Hope you guys enjoy this tutorial, took quite long for me to do. RE: PHP: If Statement - Peter L - 12-07-2011 Nice tutorial, but you're approach to teaching people wasn't very clear. If I knew nothing about PHP and tried learning from this I'd be very confused. RE: PHP: If Statement - BreShiE - 12-07-2011 (12-07-2011, 01:34 PM)Laugh Wrote: Nice tutorial, but you're approach to teaching people wasn't very clear. If I knew nothing about PHP and tried learning from this I'd be very confused. People who are that new in my opinion shouldn't be learning the If Statement anyway, it's a bit advanced for new comers. I may make a tutorial on the very basics of PHP. RE: PHP: If Statement - Peter L - 12-07-2011 Well...this is one of the first things I learned. It is very basic and does a lot.. RE: PHP: If Statement - BreShiE - 12-07-2011 That's why I thought I'd make a tutorial for it. When I get enough time I'll add in some examples on how to use it in forms etc. RE: PHP: If Statement - Peter L - 12-07-2011 That is not what I meant at all, fix what you have before adding more. RE: PHP: If Statement - BreShiE - 12-07-2011 What do you mean by "Fix" it? You mean add more of a description for each section? RE: PHP: If Statement - Peter L - 12-07-2011 I mean make what you already wrote easier to understand. Also make the code less sloppy. Simply put: You made an easy feature hard and confusing. RE: PHP: If Statement - BreShiE - 12-07-2011 I'm not all that sure on how I can make it better, I myself am quite new to PHP. |