- 5/10/2025
💻 Want to learn PHP programming from scratch?
In this full tutorial, you’ll learn PHP basics, variables, loops, functions, forms handling, and database connection — all in one video! Perfect for beginners and students starting with web development in 2025.
✅ In this video, you’ll learn:
What is PHP and why it’s still powerful in 2025
PHP syntax, variables, data types
Loops, functions, and arrays in PHP
How to handle forms and user input
Connect PHP to MySQL database
Build a simple project to practice 🚀
👉 Whether you’re new to coding or upgrading your skills, this video covers everything you need to start with PHP programming today!
🔥 Subscribe to NanoTechBoost for more coding tutorials, web development tools, and career tips!
#LearnPHP #PHPTutorial #PHPCrashCourse #WebDevelopment2025 #NanoTechBoost #CodingForBeginners #PHPMySQL #PHPProgramming #FullCourse #ProgrammingTutorial
#LearnPHP
#PHPTutorial
#PHPCrashCourse
#WebDevelopment2025
#NanoTechBoost
#CodingForBeginners
#PHPMySQL
#PHPProgramming
#FullCourse
#ProgrammingTutorial
In this full tutorial, you’ll learn PHP basics, variables, loops, functions, forms handling, and database connection — all in one video! Perfect for beginners and students starting with web development in 2025.
✅ In this video, you’ll learn:
What is PHP and why it’s still powerful in 2025
PHP syntax, variables, data types
Loops, functions, and arrays in PHP
How to handle forms and user input
Connect PHP to MySQL database
Build a simple project to practice 🚀
👉 Whether you’re new to coding or upgrading your skills, this video covers everything you need to start with PHP programming today!
🔥 Subscribe to NanoTechBoost for more coding tutorials, web development tools, and career tips!
#LearnPHP #PHPTutorial #PHPCrashCourse #WebDevelopment2025 #NanoTechBoost #CodingForBeginners #PHPMySQL #PHPProgramming #FullCourse #ProgrammingTutorial
#LearnPHP
#PHPTutorial
#PHPCrashCourse
#WebDevelopment2025
#NanoTechBoost
#CodingForBeginners
#PHPMySQL
#PHPProgramming
#FullCourse
#ProgrammingTutorial
Category
📚
LearningTranscript
00:00Well, hello, Internet! Many of you guys have asked me to do a PHP tutorial like I did with JavaScript and Java, and so here it is.
00:07In this tutorial, I will teach pretty much the entire PHP language in one video, so I have a lot to do, so let's get into it.
00:15Okay, so this is going to be the basic format for this video tutorial.
00:19Over here on the left, I have a basic text editor. Over here on the right, I have Google Chrome, and it is going to run everything for us.
00:25Now, what I did ahead of time was I went and created a basic HTML file called enterinfo.html, and right here you can see I have the PHP script that we're going to be making,
00:37and it's going to process, meaning the PHP script is going to process every bit of information that is in this basic HTML file.
00:45So, when the user comes over here and enters some information like that and clicks on submit, it's going to jump over to learnphp.php, and it's going to execute everything.
00:55And all I have here basically is just a form, and I'm going to be using the post message, which is going to send the data input into this form via a separate message,
01:05versus using the get method, which is going to send the data entered by appending it to the end of the URL.
01:10I am proposing that everybody watching this video knows HTML, but if not, I have a link in the description underneath the video to my HTML tutorial.
01:17You learned HTML in about 15 minutes with that one.
01:19Then I have a basic table here, and name, and address, and the ability to input this information, and then at the very bottom here, I have a submit button.
01:28So, very, very simple. So, let's start writing the PHP code.
01:32Okay, so as you can see here, it is still HTML, even though we are creating PHP files here, and you basically just embed PHP code between tags,
01:42and those tags would be PHP, just like this, and then it would end at the bottom with a question mark and a closing tag, and it's just as simple as that.
01:51Now, one thing to remember is the PHP code that you write here in this file isn't going to show if the user tries to view source,
01:57and very, very important, you're going to have to put a semicolon to finish every PHP statement.
02:01Now, of course, if you have multi-line comments, you're not going to have to put a semicolon after those,
02:08and also you have single-line comments, and also there's another single-line comment, which is just the number sign, so just another.
02:16Okay, so those are the different types of comments you can use inside of PHP.
02:19Now, if you use the PHP statement echo, it is basically just going to output onto your screen whatever you put between the quotes.
02:27So, you could say something like data processed, and then put a closing tag here, and then a semicolon at the end,
02:34and that's going to output that on the screen.
02:36Let's just come over here, hit submit, and you can see data processed shows up right there.
02:40Now, one thing to note here is I'm using double quotes here, and basically what double quotes are going to allow you to do is use escape sequences.
02:46So, for example, if I wanted to put double quotes inside of here around data processed,
02:51I'd have to come in here and put a backslash and a double quote, and another backslash and a double quote,
02:56and you can see that those showed up here on the right side of the screen.
02:59If, however, I was going to use single quotes, I would not be able to do this because single quotes ignore escape sequences,
03:06and you're also not going to be able to print out variables directly inside of this statement with the echo.
03:13I'm going to show you that here in a moment.
03:14Let's do something right here out of the gate.
03:16That's a little bit interesting just to show you how cool PHP can be.
03:20Let's go and print out all types of date information onto the screen.
03:24I'm going to go date default time zone set, and I'm going to use here the coordinated universal time, which is a standard to use.
03:33And then what I'll be able to do is come in here and use all of these different symbols to define exactly what type of date I want to print out on our screen.
03:41So let's just come in here, and let's just create this.
03:44Basically, what I'm going to do is I'm going to use echo again, and then I'm going to call date.
03:48And let's say that I want to put the hour, well, you can see right here, hour, 12-hour format, so I'm going to put that there.
03:55I'm going to put a colon inside of it.
03:57Then I'm going to want minutes, which is I, as you can see above.
04:00Seconds, and then U would be milliseconds.
04:03I could then type in A for lowercase am and pm.
04:06I could put a comma inside of there, then put an L for the full text for our day.
04:10Capital F for full text for the month.
04:12Day of the month, and then if I wanted to put a suffix on it like first, second, third, I just put a capital S there.
04:20Put the year in with a capital Y, and then an E will print out the actual time zone that I'm going to use, which is going to be UTC.
04:27Close that off with another single quote.
04:29And there you can see date processed, and then it's going to have the exact time in milliseconds, pm, Saturday, August 19, 2014, UTC.
04:37So I just wanted to show you real quickly how to do that, and of course, all the code that we have here is available in the description underneath the video.
04:44Now, whenever we look back at our HTML here, you can see that I have the names defined for username, street address, and city address.
04:53Well, they enter that information.
04:55How exactly am I going to be able to go in and grab it and use it inside my PHP code?
04:59Well, it's rather easy.
05:00I'm going to put a dollar sign in here, which is how you start all of your variable names, which is where you're going to store your information.
05:06I'm just going to call this user's name, and then because the HTML used the post way of passing information, I'm going to type in dollar sign underscore post, put a bracket,
05:16and then I'm going to type in the username, which is the name that was defined in the HTML code, and then go right like that.
05:23And that's going to be able to get me all of that data that was passed in there quite easily.
05:27And then I could get the street address and the city address in exactly the same way.
05:31Now, it's very important to understand how to define your variable names.
05:35Basically, they're all going to start off with dollar signs.
05:38And then the very first letter here is going to have to be a letter.
05:41And then thereafter, you're going to be able to use letters, numbers, or underscores to define them.
05:46Another thing that's important is user's name is going to be different than user's name with a lowercase n because variable names are case sensitive.
05:54And another thing that might be really weird is whenever you create a variable, it is automatically going to be given a data type whenever it receives a value.
06:02And all the possible data types are either going to be integers, which are going to be whole numbers without decimal numbers afterwards,
06:08floats, which are going to be decimal numbers, strings, which are going to be just a series of characters,
06:12booleans, which have the value of true or false, arrays, or objects.
06:16And arrays are just boxes inside of boxes, a whole bunch of different items inside of those.
06:21And we'll get more into that later on in the tutorial.
06:23And if you're wondering, by default, a variable will get the value of null.
06:27So that pretty much covers everything about variables.
06:30And let's go and echo some more information out on our screen, like our user's name that the users type in there.
06:36So you just go user's name, just like that.
06:38And there it shows up.
06:39Now you can do something called string concatenation.
06:41So let's say I wanted to put a break after every single one of these strings that I print on our screen,
06:47which would be very useful and very helpful and be able to see everything.
06:50I could then just put a period inside of here, followed by whatever I want to show on our screen.
06:56Then let's say I want to do street address and city address.
07:00Make sure you have a lowercase a right there.
07:03And then save this, jump over here.
07:04And there you can see I printed everything out on the screen and also put the line breaks inside of there.
07:08Another thing you can do with text is use what's called a here doc syntax, which is basically,
07:14let's just come in here and create a basic string.
07:17What you could do is have your string go over multiple lines.
07:20And all you're going to have to do is put these little sideways carrots inside of here.
07:24Then you're going to have to define pretty much anything that won't show up in your string.
07:28Then what this is going to allow you to do is go the customer's name is and just keep going.
07:34And then you just type in user's name and they live at.
07:39And then we type in street address in city address.
07:43And then you could throw your break statements in there if you'd like.
07:46And at the very end, you have to make sure you do this.
07:48Make sure there's no white space before this.
07:50And then you're going to type in EOD, exactly what you have above.
07:53And then you could just come in here simply and go echo and string.
07:57There you can see customer's name is Derek and they live at 123 Main Street in Derry.
08:01Come and get rid of some of this stuff.
08:03Another thing you can do, of course, is define constants.
08:06And they are pretty much exactly what you think.
08:08They are values that cannot be changed.
08:11So if I want to put pi inside of here, there we go.
08:13And then I would simply be able to come in here anytime I want and go echo the value of pi is and then uppercase.
08:21And you would want to use uppercase with all your constants.
08:24There you can see that it printed out just like that.
08:26Of course, like every other programming language, you're going to be able to do all types of different forms of arithmetic.
08:32And I'm going to show you other different ways to print stuff out here on our screen here in a moment.
08:35So let's say that I wanted to print out on the screen whatever 5 plus 2 is equal to.
08:40Put that period inside of there.
08:42And I'm going to go 5 plus 2.
08:44And let's do this for a whole bunch of them.
08:46So let's do a subtraction.
08:48And let's do a multiplication, which is a star.
08:51And let's do a division and modulus, which is going to return the remainder of a division.
08:57And, of course, change these guys over here as well.
08:59And then throw in another break statement.
09:01Another thing you can do also is let's say you wanted to cast to an integer.
09:06So let's come in here.
09:07And if we do this division here, it's going to come back 2 and a half, of course, because 5 divided by 2 is 2 and a half.
09:14Let's say, however, I wanted it to show up as an integer or cut off the decimal place.
09:19I would just put integer inside of these brackets like that.
09:22And, of course, you're going to be able to do that with all the different data types.
09:25So if you wanted it to show up as a change from an integer to a float or a double, for example, which is just a number with a decimal place, you would just type in double inside of here instead.
09:36But we're going to leave this integer.
09:37You could also do the same thing with string.
09:39Of course, just type string inside of there.
09:41And there you can see all of our arithmetic show up there on the screen right there.
09:44And you can also see this doesn't show 2.5.
09:47It just shows 2.
09:47Another thing we can do is let's come in here.
09:50You can use a shortcut.
09:51So let's say that we have a random number and let's just give it the value of 5.
09:57And we wanted to add 5 to random number and then output it on our screen plus change the value of random number.
10:03Well, we could just come in here and go random number and then plus equal 5.
10:09Or we could change that to 10 just so it's not confusing.
10:12So what this is going to do is take the value of random number, which is 5, add 10 to it, and then save it back to random number.
10:18And there you can see it shows 15 on the screen.
10:21And, of course, you're going to be able to do that not only with the plus, but you're also going to be able to do it with the minus and multiplication and division and modulus.
10:31So those are some shortcut ways to add numbers to themselves.
10:35Another shortcut we can have here is we can auto-increment by 1 very, very easily.
10:40There's actually two ways to do it, though.
10:42So let's go in here and let's just do a random number is equal to and show that on our screen.
10:47And let's just go plus plus, random number, and we'll throw a break statement in there as well and make sure it's between quotes.
10:54And then we're going to use the other way to auto-increment or add 1 to a value in a shortcut way.
11:00We're going to put the plus plus after it, and we can take that right there.
11:03And you're going to see here in a second the difference between the two of them.
11:06And there you can see it.
11:07Now, whenever you put the plus plus before the actual variable name, what that's going to do is it's going to add 1 to it immediately.
11:14And that's the reason why it shows on the screen.
11:17If, however, you put the plus plus after, it's going to use the original value for random number in whatever you're doing.
11:23And then after it's done using it, it's then going to add 1.
11:27So if you would then do an echo down here like that, now it's going to be 7.
11:32And there you can see it is 7.
11:33Another thing that's kind of interesting is you can kind of make a, either create a reference to a variable or make a copy of a variable, however you want to look at it.
11:42So let's say I wanted to go reference to number.
11:45I could then go equal to, put an ampersand inside of there, and then point at random number, right like that.
11:51I could then go into random number and give it the value of 100, and then come down here and call echo again.
11:58And I'm going to put single quotes in here this time because I don't want the value for my variable to show up here and in here.
12:05I want the actual name to show up inside of there, so that's why I'm using single quotes this time.
12:09And I could go reference to number, and you can see 100 shows up.
12:13So if the value for random number changes, this is going to change as well because I went in here and turned this into a reference to random number.
12:21So I'm covering pretty much everything here.
12:23Another thing, let's go in and talk about if statements.
12:25Now there are many different ways to compare values inside of PHP, just like most other languages.
12:31You have equal to, you have not equal to, you have less than, you have greater than, you have less than or equal to, and finally you have greater than or equal to.
12:40So let's go and use those guys.
12:43And then we have a couple other ones that are a little less known.
12:46We have the three equals in a row, and what this is going to do is say if two values are equal and the same type.
12:52And another thing you could do is go put the exclamation point in there, and this is going to check if it's not equal or the same type.
13:01All right, so let's use these comparison operators in a useful way.
13:04So what we're going to do is execute different code based off of different conditions.
13:08And an if statement works great for that.
13:10So let's say if five is equal to ten in that situation, we're going to want to put our curly brackets here.
13:16And then inside we're going to have all the code that's going to execute if that is true.
13:21So we're going to come in here and just say five is equal to ten, which we know is not true.
13:25Another thing we could do is let's say we want to check another condition, or let's go and just talk about the default first.
13:32If you put else inside of here, if five is not equal to ten, then this code is going to show up.
13:38And we'll go echo is equal to five, not equal to ten, right like that.
13:43And if we execute it, you can see that five is not equal to ten.
13:46Now what I started to allude to there is the situations in which we would want to actually check multiple different conditions
13:52and perform multiple different operations based off of that.
13:55So let's say we have a grocery store, and it offers discounts based off of the number of purchases.
14:01So let's say somebody went in and wanted to purchase four oranges.
14:05Of course, put equal sign inside of there.
14:07And then another thing the store sells is bananas.
14:10And let's say somebody wanted to buy 36 bananas.
14:13Now the store owner wants to come in here and see if the user goes and buys more than 25 oranges
14:19and also more than 30 bananas, they're going to give them a 25% discount.
14:24How are we going to do that?
14:25We're going to come in here, and we're going to say if, and we'll put multiple brackets around that,
14:29num of oranges is greater than 25.
14:33But how do we check for and, multiple different situations, multiple different comparisons?
14:38Well, we just put the and symbols inside of there, right like that.
14:41And that's going to allow us to check if both things are true.
14:44And these are called logical operators, these guys right here.
14:47And I'm going to show you the other two logical operators in a second.
14:50And we'll go num of bananas greater than 30.
14:53So if they want to buy more than 25 oranges and more than 30 bananas, we're going to give them a discount.
14:59And in this situation, we're just going to echo out on the screen, 25% discount, right like that.
15:05Let's say they want to offer other discounts, however, in situations in which they don't buy enough.
15:09In those situations, we're going to type in else if.
15:12And let's save ourselves a little bit of time.
15:14Let's just copy this, paste that in there.
15:16And let's say we're going to give them a 15% discount if they buy more than 30 bananas.
15:21Or this is how we're going to be able to check and get a true response if either of these are true.
15:28So if they buy more than 30 bananas or they buy more than 35 bananas,
15:33we're going to do a couple other nice discount things for them.
15:36And in this situation, again, we'll go 15% discount.
15:39And let's go in here and do one more so I can show you the final logical operator that's available.
15:44And that is not.
15:46So what happens if we want to check if something is not true?
15:49Well, you just put the exclamation point in there like that.
15:52And then I'm going to check num of oranges less than 5.
15:56So if they're buying at least 5 oranges or they're buying at least 5 bananas,
16:02we're going to give them a discount.
16:04And in this situation, that discount is going to be a 5% discount.
16:08And then we can use our else statement again here to handle any default situations.
16:13And we'll just go like this.
16:15And we'll just say no discount for you.
16:19And you can see right here, 15% discount.
16:21And the reason why is the bananas.
16:24I ordered 4 oranges, which in this situation doesn't fit this condition.
16:30However, I ordered 36 bananas, which does fit this condition.
16:34And that is the reason why 15% printed out.
16:36Then inside of PHP, we have another thing.
16:39And we get in a situation where we want to assign a value to a variable based off of a condition is true or false.
16:45And it is called the ternary operator.
16:47And basically, the way it works is you have your condition followed by a question mark.
16:51And then you're going to have the value that's going to be assigned if true or value if false is going to be assigned.
16:59And the basic way that this is going to look is let's come in here.
17:02And let's say we have biggest number we're going to store inside of here.
17:06And equal to.
17:07Then we're going to have our condition.
17:08So we're going to have 15 greater than 10.
17:10Of course, these could be variables and not just straight numbers.
17:13And then we're going to say that we want to store 15 inside of biggest number if it's the biggest.
17:18Or 10 if it is the biggest.
17:20And then, of course, we could go echo biggest number.
17:23And there you can see 15 showed up.
17:25Another way we could do conditions inside of PHP is using a switch statement.
17:29And you're going to use a switch statement whenever you have a very limited number of possible values.
17:34So let's say we want to make different decisions or print different things based off of the user name that gets passed in our HTML.
17:41Well, you're going to type in the variable that you're going to be checking for.
17:44User's name in this situation.
17:46And then you're going to type in case.
17:48The user's name has the value of Derek.
17:50And you can use doubles or strings or anything inside of here.
17:53Well, in that situation, we're going to type out hello, Derek.
17:56And then we could do the same by creating a couple more case statements.
18:00So let's just create one more.
18:01That'll solve it.
18:02Let's say it is Sally.
18:04And you're also going to want to come in here and type in break, which is going to throw you out of the switch statement and continue executing code afterwards.
18:10But it's not going to come down and check if it's Sally.
18:12And waste time.
18:13And then, of course, type in hello, Sally.
18:15And then we want to come in here and also type in a default answer or code that we want to have execute in that situation.
18:23And we're going to type in echo.
18:24And we'll say something like hello, valued, customer.
18:28And then type in break.
18:29And there we go.
18:30And we know that I entered Derek previously.
18:32And now you can see hello, Derek shows up.
18:34So that's a switch statement.
18:36Now, very often, you're going to want to perform actions until a certain condition is met.
18:40And a while loop works great for that.
18:43But one thing we have to do is first come in here and define some way for us to get out of the while loop.
18:48And what we're going to do is we're going to continue incrementing the value for number until it is greater than 20.
18:55And, of course, this is going to have to be created or initialized or whatever you want to refer to it as outside of the while loop.
19:01And then you're going to type in num.
19:02And we're going to continue executing code inside of this loop, which is defined by these curly brackets right here.
19:09And then inside of it, we're going to type in, let's go and auto increment that by one each time.
19:14And you're going to have to always do that inside of while loop as well.
19:16And then let's go and put commas inside of here.
19:19And we're going to print out these inside of the browser.
19:21And there you can see it was an easy way to be able to print one through 20.
19:24Another thing you can do is go and use a for loop, which is going to pretty much perform exactly the same actions that you saw with the while loop.
19:32But it's going to do it in a somewhat more compact way.
19:35So let's just leave the while loop there.
19:36And I'm going to show you how to do exactly the same thing with our for loop.
19:39And we're going to use for loops again later on in the tutorial in an example.
19:43So we're going to define number is equal to one in this situation.
19:47And I use zero up here only because I use this increment right there.
19:51And that's the reason why it's going to switch to one.
19:53And then it's going to print.
19:54Remember, that's the way that works.
19:56And then I'm going to come in here and define the condition.
19:58I'm going to keep doing this as long as number is less than or equal to 20.
20:02And then I'm going to define how the variable is going to be incremented each time through our loop.
20:08And I could just go echo and num.
20:11And then I could print a comma out inside of there.
20:13But one thing that sort of bothers me is after this 20 right here, I have a comma.
20:16It's also going to give me an excuse to go and talk about something else.
20:19So let's say I wanted to come in here and say if is not equal to 20.
20:24Well, in that situation, I'm going to print out my comma.
20:28However, if it is equal to 20, I could come in here and end this in a couple different ways.
20:33One way to stop looping is to use that break statement.
20:36Just like before, what that's going to do is jump us out of our for loop immediately.
20:41If I wanted to be really crazy, I could come in here and type exit.
20:44What exit's going to do is stop executing my PHP script altogether.
20:48I don't want to do that.
20:49I just want to stop executing the for loop in that situation.
20:52And you can see here, if I jump over, execute, it's going to print 1 through 20 again.
20:56But in this situation, it got rid of the comma at the end of the 20.
20:59Another thing that's very useful, I talked about them for a brief second before.
21:03And that is arrays.
21:05And make sure you don't have any of these little trailing little gibblies here.
21:08Because that'll cause all kinds of errors.
21:09Make sure you have everything cleaned up.
21:11Now an array, like I said before, is going to allow you to store multiple different types of values.
21:15So let's say I want to come in here and type in my best friends and store them all in one place.
21:20Well, an array is just a box of boxes.
21:23And I'm going to put Joy inside of here.
21:25And I'm going to put Willow inside of here.
21:27And I'm going to put Ivy inside of here.
21:29There you go.
21:30That is an array.
21:31Boxes inside of boxes.
21:33Now, each of these boxes is going to have a label.
21:35The very first one is going to be 0, and then 1, and then 2.
21:39And that's the way it is.
21:40However, in PHP, you can change that.
21:42If I want to echo out onto the screen some information that is inside of an array,
21:47I just type in the array name.
21:50And then put a box.
21:51And then the label for the box.
21:52Close that off.
21:53And there you can see it printed out on the screen just like that.
21:56You can also come in here and add items to our array quite easily.
22:00Just go Best Friends.
22:02And let's just give it an index that doesn't exist.
22:04Right like this.
22:05Then let's say I got a new friend named Steve.
22:07There you go.
22:08And he's in the array now with all my other friends.
22:10Let's do it in a more interesting way, however.
22:14And that more interesting way is a for each statement,
22:17which is going to allow me to cycle through all of the different items inside of my array.
22:23And all I need to do is give it the array I want to cycle through.
22:26And then, don't put that little comma inside of there.
22:28Instead, you're going to put as.
22:30And then I've got to give it a temporary holding field or temporary variable,
22:34which each of these items is going to be stored in temporarily.
22:37And then I could do something like echo and friend.
22:41And there you can see I printed them all out on the screen all in one place.
22:44So that for each block is just for arrays.
22:47Another thing you can do is create key-valued pairs for the arrays,
22:51which is very much like all of the other arrays or this one array we created here.
22:55Except in this situation, this has the key of zero or the index of zero.
22:59This has one.
22:59This has two.
23:00And this has four.
23:01If I wanted to define what the keys are going to be,
23:04I could do something like customer is equal to.
23:07And I'm going to create an array again.
23:08Then I'm going to give it the specific key I want this data to have.
23:12Equal sign with that bracket right there.
23:14And let's say I want to have the user's name be stored inside of there.
23:18Put a comma.
23:19I could then go street.
23:20That's the key.
23:21And you could store basically any type of data inside of here.
23:24It doesn't have to be using variables in this situation like I have.
23:28I could type in city.
23:30And you're going to be able to access this data using the keys,
23:33just like you used the indexes before.
23:35And then close that off.
23:36And there's the whole thing right there.
23:38And in this situation, I could still use a for each block as well.
23:42And I'm going to show you how to use that.
23:43And we're going to type in customer,
23:45which is the array I want to work with.
23:47As, and then key, and value.
23:50Key-valued pairs.
23:52Is that there?
23:53And then I could go echo, key, concatenate this,
23:56and put in a colon.
23:58And then I could type in also my value and execute that over here.
24:02And it's going to print out my name, my street, and the city.
24:06Another thing you're going to be able to do is combine arrays.
24:09This is so easy to do.
24:11Let's just say we want to store this information in best friends,
24:14whether this makes sense or not.
24:16So if I want to take the customer data and put it in best friends,
24:19like let's say I decided that 123 Main Street was a best friend, whatever.
24:23Let's just go best friends and just put a plus sign and customer.
24:27And now they are joined.
24:28They are all one array, but they have different keys.
24:32You can also do comparisons between arrays to find out if they are equal.
24:36In that situation, just use the equal sign.
24:38Not equal.
24:39There you go.
24:39It's the same thing.
24:40If you want to check if they have the same value, same order, and same data type,
24:45however, you're going to have to put three equal signs.
24:47So that's a way to compare arrays.
24:49Another thing we can do is come in here and create a multidimensional array.
24:54Let's just get rid of all of this.
24:56So let's say we wanted to go and create a customers array is equal to,
25:01and again, you're going to type in array, right like we did before.
25:04And then you just put an array inside of an array.
25:06That's what a multidimensional array is.
25:08And then we could have like customers names, for example, and 123 Main.
25:12And we could put in a zip code or something, 15212 or something.
25:17And then we want to create more of these guys.
25:19Let's go in here and just copy this, save some time.
25:21And let's say that we wanted to have Sally be in here.
25:24125 Main.
25:26And then make sure you close that off with the proper brackets.
25:29We could then cycle through these using a for loop.
25:32So we'll just go for, and we'll say that we want to get our row is equal to,
25:37and row is just a name just like any other.
25:39You can put anything inside of there.
25:40I'm just typing in row because it makes sense.
25:42So as long as row is less than three, remember, we start at 0, 1, 2.
25:46And then we're going to auto-increment row with our for loop.
25:49And then we're going to put another for loop inside of here,
25:52so we'll be able to cycle through our columns.
25:54Columns is going to start off with zero.
25:56While columns is less than three, we're going to continue cycling through here.
26:00And here we'll increment it.
26:02And then we'll close off our for loop right like this.
26:04And then we can go echo and customers, which is the name of our array.
26:09And if we want to print out the row data, do that.
26:12And the column.
26:13And then let's say we want to put a column in here
26:16between all this different data we have.
26:18And then we want to come in here and throw in a break statement.
26:21You'll see here in a second what it's going to print out on the screen.
26:24And there you can see it printed everything out there on our screen.
26:26So that's multidimensional arrays.
26:28Now there's a couple other very common array functions.
26:31Let's say you wanted to sort your array.
26:33Well, you would just type in.
26:34This is a function, which we're going to get into later on.
26:36What you do is just type in sort.
26:38And inside of the brackets, put your array name.
26:40And this is going to sort in ascending alphabetic order.
26:42If you would come in here and put another comma in right there
26:46and type in sort numeric, it'll sort in numerical order.
26:49Or if you type in sort string, it's going to sort everything
26:52as if it is a string of characters.
26:54A sort is going to sort the arrays with the keys.
26:57It's going to keep the keys together.
26:59K sort is going to sort by the key names instead of the actual values.
27:04And you could put an R in front of any of these guys right here.
27:08And it is going to give you a reverse sort, just like that.
27:11Now let's get into strings, which are just a series of characters.
27:14And let's go in here and create a random string.
27:17And let's throw some empty space here in the front.
27:20And then type in random string, right like this.
27:22And put some white space down here.
27:24Now let's say you wanted to make sure you close off
27:26with the same quote that you started with.
27:28Now let's say you wanted to go and actually trim off
27:31the white space on a string.
27:33How would you do that?
27:34Well, another thing that's very useful
27:35is to be able to see the length of the string.
27:38So you just use S-T-R-L-E-N or string length.
27:41And we're going to type in random string.
27:43And then we'll throw a break statement in there.
27:45Now if you want to trim off the left space,
27:48what we're going to do is with this guy,
27:50we're going to go L trim.
27:51That's going to get all the white space
27:53off of the left side of our string.
27:55If you would want to do pretty much the same thing
27:57on the right side of the screen,
27:59you're going to type in R-T-R-M.
28:01Not very common to use those guys though.
28:03And the number one way,
28:04I'm using string length here
28:06just to show you how the string changes
28:07based off of using these trim functions.
28:10And I'm going to use trim.
28:11That's going to get rid of all of the white space.
28:14And there you can see,
28:15the original string length was 29.
28:17After we got rid of all the white space on the left,
28:19it was 19.
28:20After we got rid of the white space on the right,
28:21it became 23 because there was more white space
28:24on the left than on the right.
28:25And then after we called a full trim,
28:27which got rid of all of the white space
28:28on the left and the right,
28:29we have a total string length of 13.
28:32Now I have been using Echo for everything so far,
28:36but there's another way to print information on the screen
28:38and that is called Print F.
28:40And you're going to use Print F
28:41because it's going to allow you to format strings
28:43on your screen just like Echo does.
28:46So let's go in here and show you the difference
28:48in what Echo would look like versus Print F.
28:51You're going to be able to use all kinds of conversion codes
28:53to convert your data as well.
28:54So with Echo, I'm going to go the random string.
28:57Now if I would put a dollar sign inside of here
28:59because this is double quotes,
29:00this would actually show up here instead of random string.
29:04Reason I didn't do that is random string.
29:07Throw a break statement at the end there.
29:08And this is the Print F version of it.
29:11Now with Print F,
29:12you're going to put the bracket inside of there.
29:14And then you're going to say,
29:15the random string is,
29:18and you're going to put a percent sign and S
29:20because we're dealing with strings.
29:22And then you're going to put your bracket inside of here.
29:24And then at the end of it,
29:25you're going to define what you want to show up
29:27where that percent sign and that S is,
29:29which is random string.
29:30Close that off.
29:31And they look identical.
29:33There you can see right there.
29:34Well, if I would have spelled random string right.
29:37There you go.
29:38Identical on our screen.
29:39One thing that is very useful though with Print F
29:42is Print F is going to allow us
29:44to use conversion codes for decimals, for example.
29:47So let's go decimal number is equal to 2.3456, whatever.
29:53Now we can go in here with Print F.
29:55You can do all kinds of other things with Print F,
29:56but I'm going to keep this somewhat basic.
29:58So let's go decimal number is equal to,
30:01and then let's say I only wanted two decimal places
30:04to show up inside of here.
30:05I could just go 0.2 and F for floating point number
30:08or a number that has a decimal place inside of it.
30:12Close that off.
30:12And then decimal number.
30:14And it's going to just show me two decimal places,
30:17like you can see right there.
30:18Now there are other conversion codes.
30:20If you want to convert an integer,
30:23so if decimal number was actually an integer
30:25into binary code,
30:26you would put a B inside of there
30:28instead of an F or an S like you saw before.
30:31Integer to characters,
30:33you just put in a C.
30:34It's going to automatically do it for you.
30:36Integer to decimal, double to float.
30:38Integer to octal number, string to string,
30:40or integer to X to decimal.
30:41Those are the different types of codes
30:43you would use in those situations.
30:44Another thing that is very useful,
30:46in regards to strings anyway,
30:48is we're going to be able to change the case
30:50of the different letters quite easily.
30:52So let's say we go echo string to uppercase.
30:55So if we want the whole entire thing to be uppercase,
30:58just S-T-R to upper.
31:00And then we type in random string,
31:02which is the string we have here.
31:04If we wanted every character
31:05to be converted into lowercase,
31:07string to, and then change upper to lower.
31:10And if we want all of the first letters
31:12to show up in uppercase,
31:14we would type in U-C first, uppercase first.
31:18And there you can see they did exactly
31:19what you thought they did.
31:20You could also come in here
31:21and convert strings to arrays
31:23or convert arrays back into strings.
31:26So let's say that I want to take my string I have here
31:29and convert it into an array.
31:31Well, you just type in explode
31:33and think of an array exploding
31:35and all the pieces falling into boxes.
31:37What you're going to do is type in here
31:39what is going to divide these strings
31:41and it's going to be a space
31:42because random string has a space inside of there.
31:44And then you're going to type in here
31:46the string that you want to explode.
31:49And let's say you wanted to also define
31:51a maximum number of pieces that go into an array.
31:54You could type a two inside of there in that situation
31:57or you could leave it off altogether.
31:58And then let's say you wanted to convert the array
32:00back into a string.
32:02You just go string to array is equal to
32:05and you would type in implode.
32:07And again, you have to define
32:08what is going to separate
32:09all of the different parts that are in the array.
32:12And then you're going to pass inside of it
32:14array for string.
32:16And in that situation, you don't have pieces
32:17and make sure you spell implode right.
32:19If you wanted to just find part of a string,
32:22let's just go part of string.
32:24You would use sub string like that.
32:28And we can come in here
32:29and let's just type in random string.
32:31You could use variables, but,
32:33and then let's say we wanted to go from the zero index
32:36and get a maximum of six characters.
32:40Print that out on the screen for us.
32:41And you can see it started at the zero index
32:44and got the first six characters
32:46and printed those out on the screen.
32:48You could also compare strings.
32:49So let's say I have man
32:51and give it a string of man.
32:54And then I have man hole like this,
32:57like a man hole cover and man hole.
33:00And that could do something like echo, string, compare.
33:03So these are really easy to remember
33:05after you use them a little bit
33:06because the names are very logical.
33:07We can compare the different strings here.
33:10See what it comes back with.
33:11It comes back with negative four.
33:12Now what this does is,
33:14if these two strings are identical,
33:16what it's going to do is return a zero.
33:18If it returns a positive number,
33:19which here it did not,
33:20it returned a negative four,
33:22that means that string one, or man,
33:24is greater than string two.
33:26It's just alphabetical order.
33:27And if it returns a negative,
33:29that means that string one is less than string two.
33:32And then you could also come in here
33:34and go string case compare
33:36if you want to completely ignore
33:39the case of the letters.
33:41A couple other ones we can use here,
33:43little string functions is string string.
33:45So let's say we go echo and the string, string, string.
33:51What this is going to do is return every character
33:53after the string that we are going to be looking for.
33:56So in this situation, dollar sign,
33:59and let's type in random string that we had before.
34:02It's going to return everything in the string
34:05after it locates the word string inside of it
34:08or the string inside of it.
34:10The string string, see,
34:11that's the string of random string.
34:14So it found string and it's going to print out
34:15everything that follows thereafter.
34:17And you could of course come in here
34:18and put an I inside of there
34:20and it is going to be case insensitive again.
34:23Another thing we could do is,
34:24let's say we wanted to get the location of a match.
34:28You would just type in string position
34:30in this situation and execute.
34:32And it's going to come back with seven,
34:34which if you count over, it is string.
34:36The S starts as the seventh character
34:39inside of this string we have right there.
34:41And then we could also come in here
34:42and replace strings.
34:44So let's say we go new string
34:46is equal to string underscore replace.
34:50And let's say we want to replace string
34:53with the word stuff
34:54in the string called random string.
34:58And we could go echo.
34:59And now it says random stuff
35:00instead of random string.
35:02And I guess that basically brings me
35:03to the final thing I'm going to cover,
35:05which are functions.
35:05If you want to create a function,
35:07which is going to allow you
35:08to reuse your code over and over again,
35:09you would just type in function.
35:11And then you could do something
35:12like add numbers,
35:13which is going to be the numbers
35:15or the name of the function.
35:16And then the different attributes
35:18that you're going to allow
35:20to be sent into this function
35:22to be executed.
35:23And you're going to have
35:23your curly brackets again.
35:25And then you could have
35:26a return statement,
35:27which is going to return numbers
35:28after you can put any code
35:30inside of here.
35:31But let's just say
35:31that we want to come in here
35:32and add these two numbers together
35:34and then return them
35:35to whoever calls
35:36for this function to execute.
35:37And then to call this function,
35:39we could just go echo
35:40and do something like
35:41three plus four is equal to.
35:43And then a period
35:44and add numbers.
35:46Three comma four.
35:47And that's going to pass it in there
35:49and it's going to echo
35:49all of that information
35:51out on the screen.
35:51And there you can see
35:52three plus four is equal to seven.
35:54So there you go, guys.
35:55That is a rundown
35:56of pretty much everything
35:58about PHP,
35:59except for regular expressions
36:00and object-oriented programming.
36:02If you guys want me
36:02to cover those,
36:03just leave a question
36:05or comment down below.
36:06Otherwise, till next time.
Recommended
9:49
|
Up next
0:37
0:11
1:24
3:12