Basic PHP Tutorial 5: If else and else if conditional statements
Key Takeaways
Demonstrates if-else and else-if conditional statements in PHP
Full Transcript
hello and welcome to the fifth php tutorial in this tutorial we're going to get into one of the more basic functionalities of pretty much any programming language you have like if else statements and then you have four and while loops um that are pretty much in every single language so let's do the if statements first and you you don't have to follow if with else um but you can follow it with else but for now all we're going to do is show you a quick if statement the syntax for an if statement is you say if and then in the in parentheses you specify whatever um the case that you're looking for is and then um what you actually produce if that is the case is within these curly braces so um and with python i'm not going to get too much too into depth about this but um they call this kind of like your standards and you could in theory code everything on in one line you or or like you wouldn't have to indent but generally what you do is every time you have like a new um statement of some sort or something that's within a parent of something else so in this case whatever is encased in this if statement like what you want to do you would code it here and say stuff you wouldn't want to encode it here and say stuff so anyway um we'll get more into that and i'm not really or at least you'll see me using these standards it's just a good idea to get used to them because for one for you to read your own code and then also for other people to ever read your code if you're ever working with somebody or if you have like a question nobody wants to answer your question if your standards are horrible and they can't read your code this is really just kind of a pain so anyway keep that in mind because like some languages like if you're coming from python it just automatically gives you beautiful standards it doesn't request that you do any of this so if you're not used to it you'll just have to start doing it so let's do if and we'll do name and then the way you do this is if an irregular equal sign is an assignment this is a double equal sign is a comparison so if name equals and we're going to say harrison um then we want to do something right we've already said it equals harrison so this will be the case now you might also see and we'll go into detail with this um in another video but you might also see triple equals in the case of string data it's not as as useful as if like if we were doing age like if we had an if statement regarding age you don't type this out with me i'm just going to show you like if we did if age equals 99 that means one thing but if you said if age triple equals 99 this would be true but if you said if age equals just 99 like the integer type of data this would actually return a false value but if you did if age equals equals 99 it would return a true so double equals just tries to compare it on you know the value itself not data type but a triple equals is going to require the exact same data type so anyway just keep that in mind it really doesn't matter in this case i'm just going to use double equals when you're comparing string data it's not as big of an issue unless it has you know numbers within it so we're going to say if name equals harrison now within this you can do this is where you're going to code whatever you want it to do so we're going to say echo and let's just have it echo strong hello and then close off our strong tags close off our statement and that's it so we'll save that put it up on the server and actually let's delete this part so we don't see a bunch of different code and we'll refresh and obviously name did equal harrison so it says of course hello harrison
Original Description
Link to the full playlist:
http://www.youtube.com/playlist?list=PLQVvvaa0QuDcYpcjrNB43_iKqla5UeQw_
Sentdex.com
Facebook.com/sentdex
Twitter.com/sentdex
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 27 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
▶
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
Related AI Lessons
⚡
⚡
⚡
⚡
The Future of Technical Education: AI, Projects, and Industry Collaboration
Dev.to AI
I Asked Gemini AI to Preview My Haircut Before My Salon Appointment - Here’s What Happened
Medium · AI
Top Five Free AI Tools in the Industry
Medium · ChatGPT
7 Best AI Tools for Research, Coding, and Development in 2026
Medium · Data Science
🎓
Tutor Explanation
DeepCamp AI