Basic PHP Tutorial 6: If else and else if conditionals cont'd
Key Takeaways
Uses if-else and else-if conditionals in PHP by declaring and manipulating conditional statements
Full Transcript
foreign so building on that last let's do the full if else and then um we'll also discuss if else or else if rather sorry um so let's go ahead and we'll delete this again and we'll rewrite this again and so now what we want to say is like what let's consider if else statements so again the Syntax for an if statement if and then parentheses the rules to this if then the actual code of this if is in curly braces and we want to keep our structure decent um then if you want to throw in an else statement you would throw else here and then there are no there's no rules to announce because the else rules already exist if this is not the case then do this so then again curly braces and you're going to specify stuff within here so let's do some work with age and I'll also show you again with the assignment operator of equal equals versus equal um so let's say if dollar sign age equal equal 99 right so now we're using the integer value instead of the string value Echo true we'll just do this um else we'll have it Echo false save that throw it up on the server refresh the page and it equals true but as I was telling you before now let's compare not only you know value but data type save that put it up on the server and refresh the answer is false because it is not the caves now you can start to get quite Dynamic with uh if and else statements so another thing that you can do is say you just you don't want to have this so you could in theory you could run another if statement if dollar sign age and let's turn this into an integer so we can use some other comparisons again I'll go over uh comparisons um in another tutorial but let's just use a greater than sign so this is going to say if age is greater than let's say 50. then we'll put in our brackets what we want to do Echo it is greater than 50. so even if this if statement is true this if statement is still going to run so let's save this and we'll run it and we didn't use any breaks but we got true and then it is greater than 50. so both of these statements ran even though this was true but as you remember before if we made this the else statement and we'll just do it is not and refresh and we didn't do it this this always like to forget those semicolons anyway it all it never ran the actual it is not because it was true if else but then the other thing you can do is if age uh equals let's say we want to do a hundred now that else will be triggered so refresh and it says it is not but another thing that you can do is what is called else if and an else if statement is very similar to an if so you can do else if put in your parameters age equals uh let's do uh we'll do 99 just to show you a success same thing as before and then we'll Echo it does indeed equal 99 close that off save it throw it up to the or the server save and then you get it does indeed equal 99. right so it's another if statement that before I showed you if you just had two if statements both if statements would indeed run even if one was true and the other one you know was true this one however won't run again if um we are right in the first one so as you can see we'll refresh again it just says true it never got to the next one because it's an else if and then finally you could have um just an ending else statement um down here just like you've got because this is really an if-ish statement um so you can end with else um Echo nothing worked something like that right and so neither of these will be true we'll put this up on the server refresh the page and you got nothing worked so naturally there's a lot of different uh ways that you can use this and kind of work with the if else else if um logic because the elsif is just a good way that it will only ask that question if the first question was not the case whereas like an else is kind of like a default like okay well if we didn't find anything just do this you know so anyway keep playing around with that until you're pretty comfortable and as always thanks for watching and until next time
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 · 21 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
▶
22
23
24
25
26
27
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
⚡
⚡
⚡
⚡
How to Create a Second Version of Yourself Inside Obsidian Using AI (Step-by-Step Guide)
Medium · ChatGPT
How to prepare for Spain civil service TIC exam using AI in 2026
Dev.to · David García
Going Viral! How I Created AI Kissing Videos Step by Step Easily Using AIAI.com
Medium · AI
How to prepare TIC teacher exams in Spain with AI (oposiciones 2026)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI