PHP Basics Getting Started | Laurence Svekis | Skillshare
Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
24 Lessons (1h 41m)
    • 1. PHPbasics

      2:08
    • 2. 1 PHP summary

      2:26
    • 3. 2 Course PHP introduction

      2:14
    • 4. 3 What is PHP

      4:08
    • 5. 4 Setting Up Localhost

      6:21
    • 6. 5 My Environment and editor setup

      2:40
    • 7. 6 PHP's configuration first code

      4:43
    • 8. 7 PHP code commenting

      3:01
    • 9. 8 Output to HTML

      4:41
    • 10. 10 Introduction to Variables

      3:43
    • 11. 11 PHP Variable Types

      5:48
    • 12. 13 Working with Arrays PHP

      8:06
    • 13. 15 PHP object quick overview

      6:22
    • 14. 17 PHP constants

      2:44
    • 15. 19 PHP Arithmetical Operators

      2:46
    • 16. 20 PHP Assignment Operators

      2:52
    • 17. 22 PHP conditional statements

      4:49
    • 18. 23 PHP switch Statements

      3:33
    • 19. 25 PHP Logical Operators

      2:56
    • 20. 26 PHP ternary operator

      3:14
    • 21. 27 PHP String Operators

      2:18
    • 22. 29 PHP Loops

      6:31
    • 23. 31 PHP functions

      10:29
    • 24. 33 PHP conclusion

      2:34

About This Class

Fast paced course perfect for beginners to learn the basics of writing PHP code.  Learn about variables, loops, functions, conditional statements and a whole lot more.  All the source code is included to get you started quickly.

Explore PHP coding learning the basic syntax used to write PHP applications.  Find out more about PHP how it works and how it can be used to write applications.

This course is designed for beginners, it will walk you through learning the very basics of PHP coding.  

  • Learn about how to setup a PHP environment to prepare to write your first PHP code
  • How to apply comments within the source code
  • How to output PHP values for web users
  • Explore how variables work within PHP
  • What arrays are and how they can be used to hold value
  • See how operators can manipulate variables values and can be used to make your code dynamic
  • Discover the power of conditional statements
  • Learn how loops can be used and the different ways of setting up loops
  • Find out more about functions and how they can help write code better.

Source code is included, as well as links to resources and information about setup of resources.   This course will help you get started with PHP and by the end of the course you will be creating your own PHP applications.

The course covers all the fundamental core concepts needed to get started quickly with PHP.  Learn and practice the code presented within the course to discovery what you can do with PHP.  PHP is one of the most popular programming languages today.   PHP is flexible and allows the developer an easy to learn programming language that can be very powerful.

PHP is everywhere and learning more about how to code using PHP is an in demand skill.   I'm here to help you learn about PHP and ready to answer any questions you may have.  Start coding PHP within minutes let me show you how.

Transcripts

1. PHPbasics: I'm so excited to have the opportunity to present this course to you today. This course is perfect for anyone that wants to learn more about PHP. It's a fast paced course ready for beginners to learn the basics of writing PHP code. Learn about variables, loops, functions, conditional statements and a whole lot more. All of the source code is also included within the course. To get you started quickly explore PHP coding. Learning the basic syntax used to write PHP applications. Find out more about how PHP works and how you can write your own applications. This course is designed for beginners. It will walk you through learning the very basics of PHP coding. Learn about how to set up your own Pete's P environment and prepare to rate your first PHP code all within this course. How to apply comments within source code. How to output PHP Values for Web users explore variables and how they work Within page p A raise and what they are used for and how they can hold values. Operators used to manipulate variables and making your code more dynamic. Disk other. The power of conditional statements learn about all the different ways you can use loops to save you time. Find out more about functions and how they can help you write code better and quicker. Source code is included, as well as links and resources and information about how to set up those resources. This course will help you get started with PHP, and by the end of the course you'll be creating your own PHP applications. This course covers all the fundamental core concepts needed to get started quickly with PHP . Learn and practice the code presented within the course to discover what you could do with PHP. PHP is one of the most powerful and popular programming languages in use today. It's flexible and allows the developer an easier way to learn programming. PSP is everywhere and learning more about how to use PHP and right PHP code is an in demand skill. I'm here to help you learn about PHP and ready to answer any questions. You may have start quoting PHP within minutes. Let me show you how 2. 1 PHP summary: welcome to our start guide to Learning the basics of PHP. This course is designed to cover off all of the basics for beginners in order to get started to code. PHP script. My name is Lawrence, and I'm gonna be your instructor for this course. I've been quoting PHP since 2002. I come to you with a lot of experience in PHP and PHP is by far my favorite coding languages. I love and always have enjoyed creating applications with PHP. One of my favorite things about PHP is its flexibility and the freedom that allows. When you're creating code, it just feels right. When you're writing cold with PHP, it's very forgiving. It's very easy to get started with. And as for scripting languages, it's probably one of the simplest ones. Toe learn. You can really learn PHP being self taught with PHP just by learning some of the core principles and basics, having a basic understanding of PHP and then building on that, creating more and more complex applications. So I do advise within this course I've provided the source code, and I do advise that you tried it for yourself. See what you can make happen with PHP. This is the PHP logo, and there is a ton of green information online for PHP as well, a lot of code snippets and so on. And there's really some amazing projects that have been launched with PHP. A lot of the main CMS systems like WordPress and Drew, Pole and Djamila. They're all based around PHP. There's a lot of really popular framework such as La Ravel. Once again, PHP and a lot of the main websites such as Facebook are based in PHP, so learning PHP opens up a lot of doors and there's a lot of opportunity. Create PHP coded applications and you can run Web applications and websites with the back end of PHP, creating database interactions and a whole lot more. Your imagination is on Li the only limit to what can be created using PHP code. So when you're ready, let's start learning the basics off PHP 3. 2 Course PHP introduction: welcome to our quick introduction to PHP and learning to code PHP within this course. I can teach you all the basic fundamental concept that you need to know in order to get started and building applications using PHP, we're gonna be going through what PHP is, how it works and the basic foundation of PHP. I'm also going to give you some suggestions on what you can do to set up your environment, your work environment to practice PHP also giving you some information of the enter that I'm gonna be using within this course as well. We're gonna look at PHP commenting how that's done, how we can output content that's readable and usable within Web pages. Also looking at variables. Of course, there's a whole lot of information within variables, including different variables types. That's all going to get covered within this course, also understanding of a raise essential part of working with PHP. We're also going to briefly look at objects and PHP and then also look at PHP Constance which are different than variables. And then we're gonna look at all the different operators that are available four variables within PHP. So there's arithmetic operators assignment operators and then how we can apply those operators within conditional statements. Also looking at switch statements, looking at logical operators, comparison operators, conditional operators string operators than showing you how loops work so different types of ways of looping. And then finally looking at functions and arguments to summarize all the basic functionality contained within PHP and giving you the capability and the know how how to start rating PHP applications. So all this and a whole lot more is covered within this course. Also, source code is included, so you two can get started quickly practicing and learning PHP. 4. 3 What is PHP: this lesson, we're going to give you a quick overview of what PHP is, how it works and how you can use it in order to render out code visible for Web pages. So PHP as a server side script, which means that runs on the server and what gets visible from PHP is actually the output off the language. So the server renders through, reads through the code the PHP code and renders out something visible in order for the Web browser to be able to, then pass that along and create something visible for the Web user. So this is a general purpose programming language. It's really straightforward and easy to get started with I. It's open source as well, and it's also works very similar to other programming languages. All the lions will end in the semi colon as we've got the example here. Also, I'm going to show you how PHP handles white space and overall, how the code works so you can get the basics of started to write PHP code and start getting familiar with writing PHP code within your Web applications. It's a few websites to get familiar with in order to learn more about PHP. So the main website is PHP dot net, and it's got a whole bunch of information. Everything PHP here s so as we can see, there's different versions of PHP. So currently, as we're making this video, the current version of PHP a 7.12 and as mentioned before, we are gonna be going over the basics of PHP. So a lot of that sin tax hasn't changed between the different versions and eso We are going to be giving you the basics, the fundamental concepts of PHP, and that's where we're gonna be going over within the course. So it will actually work on the previous versions as well, as well as the current version of PHP. And a lot of Web servers will still be on PHP version five as there was a big difference, a big change in between five and seven. So seven was a really big jump forward. So a lot of servers air still on the 5.45 point 55.6 versions. Eso you'll see that very often so it is important also to understand what PHP version is available on your system and I'll show you how to find that out simply by writing some PHP code and you'll be able to find out. Actually, information about your PHP set up show how to do that in the upcoming lesson. So again, there's some more information about PHP licensing. So we've got open source license from PHP, and it's available. Here's the use of the logo and so on. It's a lot of good information here within help to find out more about PHP and what how to use PHP, which is also available within the documentation section of PHP dot net ducks. And I'll give you all that information as you can see various languages and so on. So as mentioned, PHP is a server site language. So basically that what means is, if you're looking to practice PHP than you need tohave a server in order to run that PHP code, it's not going to render out within your browser simply by going over the file like HTML. CSS and JavaScript does so well that gets rented out using a browser. But for PHP, we need something a little bit different. We need to have a server running as mentioned before it is the server that reads the PHP code. And you do need tohave a server running in order to read out that PHP code. So in the next lesson, I'll show you now set one up on your system So you two can practice PHP right within your own computer system without actually having Teoh transfer files to a server and so on. So that's coming up in the next lesson. 5. 4 Setting Up Localhost: the previous lesson. We gave you a brief introduction to what PHP is and how it functions and where you can get some more information on PHP. And we also did mention that you do need to have a server in order to run PHP on your computer. Or you didn't need to have a server in order to run and render out PHP code eso There's a several different options that you might have. You might have access to, Ah, hosting account, and it may be able to upload your files toe there. So do a file transfer, and this is actually makes things very difficult, especially in trying to practice PHP. It's ah, it's more time consuming that you have to transfer the files so I usually suggest to set up a local machine to run on your own computer system. And there's a really good one called Zampa, and that's available at patchy friends dot org's s. So this is probably the easiest one to download and install. It's pretty quick to install. It's fairly lightweight and easy installation, just a bunch of clicks, and you can click through and be up and running and literally just minutes, and this what what it will give you is it will give you the ability to install a PHP server on your computer. It also gives you a database and allows you to run all of this locally within your own machine, and you can download it on various platforms. So there's Windows, Linus and OS X. So whatever platform you're looking to download it on its available example. And this is another really good reason why I usually use Samp is because it's really, really easy to install, and it works across different platforms. So right now I'm on a Windows machine and I'll show you what Samp looks like on the Windows machine. It is not a whole lot of difference between the way that it looks on the different machines . And essentially what it's doing is it's going to give you the ability to write PHP code and practice it right on your system without having to FTP and I will show you that up and running and working, how it looks like and how you can get yourself configured really quickly. So go ahead and download Samp, and if you already have a way to get a local machine and you have PHP installed and set up . Then you can go ahead and you can skip through the rest of this lesson as I'm just gonna be explaining how to work with Zampa and end result is that I'm gonna have a local machine. So something like this where I can go to a local host and I can see whatever file I've pointed to as the default directory for the local host. So go ahead, download it. And once you downloaded it, then you can open up the control panel. So essentially, the Zampa control panel is where all of your config settings to start up your Apache machine to start up your database. If you want to run FTP server, you can start up files Illah. And this is another way that you can ftp files right into your local file system. Eso This is another option. I usually don't use this one. I usually just point the directories to wherever I've got the folder where I've got my files that I wanted to utilise eso There's a few options here here. We've got an option to select the editor that we want to use. We can also auto start several modules Right now I have brackets as my default editor and I'm just going to change that to note pad eso Now I'm gonna use note pad plus plus in order Teoh use as my default editor. And I believe by default it's going to be text pad. So all that did is when you hit config and you hit your http dot de config file. You get access Teoh, your http config file s Oh, this is it. Opening up here and here. I've got all of my configuration information, for example. And the reason I'm showing you this is because I want to show you how you can actually change your root directory. So by default it's gonna go into Zampa HD docks. And if you've got your file sitting somewhere else on your computer as I do, then this is just a quick work around toe. Actually, get your files to point somewhere else. So I want it actually, my files to point my document route to be K Websites and Apps folder called PHP. So we all have to do is just change document root and change. It to whatever path it is that you remain. Folder root folder of your file system is going to sit on, and that gives you the ability to open it up in an editor. So sear. I've got that same PHP folder. And essentially, this is gonna be my home page. I can type in something like, Hello, world, Go back out, Refresh local host. And there we go. I'm actually out putting that same index peach that I've got that I'm working on within Adam, which is my editor s. Oh, this is just a quick way to get up and running. Of course, you could use the default directory, the HT docks default directory, for example as well. And you could work out of that directory if you wanted to. So once you have it up and running, you could always test and see if PHP is working. And I am gonna walk through the syntax in the next lesson as well. So basically, it's opening up PHP and using that syntax for PHP. And what I'm gonna do is I'm just gonna echo this s o. This is a way to output that content. And so now, when I refresh it, We actually don't see a change. Even if I go to the page source, I just see the output of the world s. So basically that means that my PHP server is up and running, that I'm able to create code within my bracketed area of my PHP files. So this just basically means it's a quick check to see if I'm up and running. So the next lesson we're going to dive deeper into PHP as well as I'm going to go over the editor that I'm using. So I'm gonna give you a brief rundown of Adam and that I'm using that for my editor. So that's coming up in the next lesson. 6. 5 My Environment and editor setup: So this lesson I'm gonna be going over my editor that I'm using. I'm using Adam. And of course, if you already have an editor that you're comfortable with using that you can go ahead and use that when you could skip over this lesson. This lessons essentially, for those of you that are looking Teoh, mimic the environment that I'm working in and use the same editor that I'm using and that is Adam. So Adam is a free editor that you can get at adam dot io and it's a really good editor. It's got a lot of great functionality Kloss Cross Platforms s. It works on Macs, Windows and Linux. It's got a really built in good built in package manager. It's just got a good way of editing code. Another thing that I really like about it is ability for the multiple panes eso You can split Adam into multiple pains, and it's just really easy to work with. It's got a good set of themes eso all of these themes air available here. All of these packages are available here and so on and again available at adam dot io. And again, this is just the editor that I'm gonna be using and just to quickly go over, it s oh, what I'm using is I've got several packages installed, and the way you can do that is you can see all of your information under setting Siegel file settings. And here have got the packages that I've gotten installed already have a ah language PHP package that I've got installed. I've also got several themes that are available so you can select various themes here and quickly install them and get them up and running within your system. And then you could simply select the ones that you want to use from the drop down menus. There's some basic information here about the editor, so I've set my fought size to 36. So it's relatively easy to read as I'm doing the screen capture here and so on. So those are the basics of the settings, and there's really not a whole lot that you usually have to do in order to configure, to get up and running. So you don't actually have to install that package either for PHP because we're not gonna be utilizing it. It just what it does is It gives me these options for the PHP code, so you might find that helpful. And also you might find that a hindrance if you're just learning to write the code. So sometimes it's better to write a day. But instead of having an auto select like that, but whatever you feel comfortable with, feel free to use that format. Eso again. This is Adam, and in the next lesson, I promise you were going to get to rating some PHP code, so that's coming up in the next lesson. 7. 6 PHP's configuration first code: This is the most exciting lesson, because this is the lesson where we're going to start, get our hands dirty and start writing some PHP code. So essentially, PHP syntax is very simple and street for less than sign question Mark PHP. And then all of the code goes here in the middle and then question mark and greater than sign, and that closes off the court. So notice no spacing between those and all of the code will go in the middle there. And this just basically means that if you've got a file and extension is dot PHP that the server knows that it should look at this as PHP code. And all of the PHP code it needs to render out is enclosed between these two uh, the these two PHP closing and opening tags. So let's open up her editors start up our local machine. So I've got that started here in the background of hit start on Apache, and we don't need to use my sequel, but you can start that as well. So I do have both of those started and I've got my Adam editor opened here, and I have my PHP ready to go. So I've got PHP opening. I'm ready to start writing some PHP code. And there what is one thing I did want to mention? Sometimes you might see PHP code written with just this type of shorthand where we've got the less than sign question mark, question mark greater than sign. And that's opening and closing the tags. So this works on some servers again, depending on how they're configured, it might not work on all servers. Eso, just to be safe, usually keep using the long format or the typical standard format here, where we've got the question mark and we write out PHP so again some servers, it's not required. And it also depends on how your server is configured. And in order to find out actually more information. While we're talking about server configuration, we can find out simply by typing in this function. So this is a built in default function within PHP, and this gives us the ability to actually pull out and find out information about our server centers settings. So this is gives us information about the PHP configuration system system settings, and when you type this into the local host So this is what we had before. And when I refresh it, we see we've got all of this information in regards to PHP. It gives us information where that PHP I and I file is sitting where configuration file is sitting and just a whole bunch of really good information that we can utilize. We're building out our applications. It gives us additional information on the versions, the different files that are supported, our server configuration of Apache machine. Our ports are server administration. Ah, and so once there's a lot of information that's contained within here. And as you can see, it's a big, huge file and this is all rendered out from the server and we actually go into and we see the source code for here. You'll see that all of that source code is written out as HTML. We've got our CSS and all of that information. We've got the images there. So this is that PHP image there. PHP local. All of it gets rendered out so all of this information is actually stored within the PHP server, and that simple function pulls that information out and lets us know what the configuration is and this is important to note that the way that PHP works is that we don't actually see what the PHP code is. But we do see what the result of that coat is. So it's the same thing as when we type in something like Echo and we do hello or something like that, then we don't actually see that we've got opening PHP Echo. Hello. We don't see all of that when we refresh it. Always see is just that output that's being rendered within the server file. And then the browser comes in and it sees it's got Onley Hello written here. Notice no HTML. There's nothing else that's contained within here. And it's as if I've gone over to my file and I've simply types pillow into the file, so it's gonna render that the same way. So the next lesson we're gonna look at Echo, we're gonna look at out putting content within the the Web page and and more so that's all coming up in the next lesson. 8. 7 PHP code commenting: every time you're writing out code, it's always a good idea to write out and comment out important information within the code . So PHP has several different ways to comment out. Content us. We can either use the hash and we can comment out a single line. We can use the slash slash and commented a single line where we could use a slash Asterix and comment out multiple lines. And one of the really cool things about PHP is that you, the Web user that's come into the Web page, doesn't actually see what's contained within the PHP code. So your comments within your PHP file are completely private. So if you want to write out something like message to users, so do you think that this will show up or what do you think will happen? Here s so again, this is commented out. And remember that the Web browser is Onley rendering out the code that is specified within the PHP code. So let's take a quick look and we'll see what this looks like. So we refresh it. All we have is hello. We refresh the source code and notice that we don't actually see the comments. So if we're writing out HTML, we'd actually see all of those comments, and the Web user would be able to see our commenting within the source code. But this is definitely not the case when it comes to PHP. And this is one of the really great advantages of PHP and writing. Server site code is that you do have this ability to comment information and to render out stuff that can remain within the scripting language without the user even knowing that it's there. And that's the one of the big benefits of writing PHP. So just to finish this lesson off eso, you can comment with the hash so you could comment with the hash. You can also comment out multiple lines. See, sometimes you'll see it like this where you've got multiple so multiple line comment and then just or close that back off when you finish writing up your comments. So here you can write again, you can write your code and so on. So all of this information, just to show you once again you're not gonna see anything within the page source. All you see is the code that's supposed to be rendered aid and visible to the Web user. So all of that commenting gets saved and stored within the PHP file and is only for consumption for someone toe actually, looking at that PHP code itself. In the next lesson, we're gonna be looking at what Echo does and how we can actually write out content. That's consumable by the Web page browser and the Web user, so that's coming up in the next lesson. 9. 8 Output to HTML: in the previous lessons, we've looked at briefly how we can render out some visible content for our Web users. And predominately, we were using echo. So echo is the command in order to render out your content so it's visible to your Web users and another one that you can use if you don't want to use eco, you can also use print, so print gives you the ability to render out that content and display it out. So out, putting essentially out putting a string value for to be usable. Eso One thing to note with PHP. It's not actually case sensitive, but by default usually were writing the functions and the PHP syntax were writing it as lower case because it just simply it makes it easier to read. So it's open up our editor, and we did right echo over here and just so that we can compare. You can also write it in upper case. So I'm just gonna do hello to go to render it out and we see that within the source code, it gets all rendered out. So notice us well about even things like white space, how that gets handled so I can have a whole bunch of white space here and again. It's on Lee rendering out that content that's meant to be visible. So only the stuff that's contained within the quoted section eso another way, too. I would put content wrote, put a string so we can do things like Prince and we can bracket around it. And then we can quote So hello world. And if you actually do want to write out some HTML, you can just write out some HTML like that. We can also do a print across multiple lines so we can open that up and we can write hello and have a bunch of space there and then maybe world down here. And as long as we're closing that off with the semi colon, just show you how this is going to render out and notice that the formats lately different . And this is one of the good things of that PHP because I always find that it's really, really forgiving. It allows you to be very flexible with the way that you're writing code. Ah, and whatever your style might be so generally this doesn't really look good. It's not really readable, but it'll work eso just to show you how this is gonna look like. So when I refresh it, we've got it written out here, and if I Reese trash it, we see that it actually renders out that PHP code. It removes out a whole bunch of that white space and it renders it, although so I know that's a little bit jumbled. There s so let me get rid of some of that white space and bring things a little bit closer together. But this is just to illustrate the point that whitespace how it gets handled, how comments get handled and so on. So this all makes it all readable and visible. So you get rid of a lot of that stuff that I had there earlier, and we're just going to simply and you get rid of that as well. Eso one other thing I did want to note you might have noticed that sometimes I'm using the single quotes. Sometimes I'm using the double quote s so there's various variations you can do about this . So if you had a bunch of hellos and you had quoted s so you see the here that we're actually breaking out of our quarter area S O. This is a problem within PHP or rendering out the code. So if I did it within print here and if I did hellos and I did the single quote, we're still okay here. Just gonna get rid of this line as well. Eso one of the things that what we do with PHP Sometimes we need Teoh break out or escape certain characters. Eso In this case, we want escape. That s so all we have to do is to a slash and this gives us the ability to still render out that that code properly, or what's supposed to be rendered out. And maybe I should put some. So I just put a simple HTML line break there between all of those and just see that it actually renders out in the same format. So I did want to mention that there is a difference between the way that PHP handles single quotes and double quotes, and this is gonna be more specific when it comes to variables. And that's something we're gonna look at in the upcoming lesson. We're gonna talk more about variables and also talk about how it differs 10. 10 Introduction to Variables: at the very heart of what PHP can do are variables, So variables are the very core of any programming language, and what variables do is they allow you to assign values Teoh a particular holder or container of that value, and that gets represented by, ah, customized name that you can create. So there are some rules in order to create variables so quickly run through the rules and I'll show you how to create your first variable. So one of the rules when we're writing PHP code is that it needs to start with a dollar sign, and that dollar sign can be followed either by a letter or an underscore. So I've got an example down here at the bottom where I've got dollar signs, my variable. So that is a typical way to set up a variable. We've also got assigned values using operators, so we used the operator equal signs to make that assignment for the value because, as mentioned variables do contain information, so they contain values that can contain strings, they can contain numbers and so on, so all of this can be contained within a variable. Also, variables can't start with a number s so they have to start with a letter and then they can contain a number. Also, variables can convert two different types as needed. And that's one of the advantages again of PHP and why PHP is a fever programming language of a lot of developers. Because just this ease of use and that just makes sense that the variables contar convert to different types s so they can contain letters, numbers and underscores within the variable name. So it's open up her editor and create some variables. So opening it up and first of all, we just defining that variable. So we just call it my V A r. And this variable we're gonna hold a string value. So just like that, and the variable holds a string value we can do, var equals, and then we can also who have a numeric value. We can do our A and have that in equal of boolean value. And I'm gonna talk more about thes later on as well and so going out to our output of our PHP code. So take a quick look and when we refresh it, we don't see anything in the source code because, remember, with PHP, we haven't specified what output we want toe output for the Web user. So all of this PHP code is just simply running in the background. These variables are being held, and it's only until we go and we do something like echo out the value. So we're gonna echoed that first variable value. At that point, then the user, the Web user can come in and see the value that's contained within that variable. But again, they have no idea how it's being output. It could be just output as echo, and then the value the string that's being contained or they don't know that it's actually sitting in a variable, and we're using the were only calling out that variable value, and this is a real advantage again to PHP, because we can have a whole bunch of processing here and then finalize that by out putting that content and making it visible to the Web user. So the next lesson we're gonna talk more about the different types of variables and show you how you can set up variables and utilize those variables within your Web code. So it's coming up in the next set of lessons 11. 11 PHP Variable Types: in the last lesson, we briefly showed you some different types of variables, so showed you strings. So essentially strings is a sequence of characters represented by text. So something like hello worlds we've got variable name equals or signing of value to it and equaling it to hello world. So this could be either single or double quotes. Ah, we also have integers eso it must contain at least one digit within the integer. So we've got the variable here as 100. We also have double, so the double is differs then an integer because it gives us the ability to go to decimal points as opposed to an integer which doesn't go to decimal points. Eso that's just the difference in the different types and also Boolean. So bulletins are either true or false So we can set those variable values as we've done here to false or to true And then this way, these air perfect for when we're doing conditions to see if a value is true, then we can execute out the condition on. Of course, we're gonna be talking about that in the upcoming lessons, more details about that and then, of course, If it's false, then it doesn't execute at that condition. Ah, and lastly, we've got No. So if a variable has a null value, then we could just do variable equals. No. So, loser, essentially the core types of variables that we can create Eso strings, integers, doubles boo leans and nose eso We've got a variable as an integer We could easily turn it into a double or so on just by representing it with a dot and some additional values to it . Eso here we've got all of the examples and one thing I did want to know what? That we can do it with single. We couldn't do it with double quotes eso it's just Adam there updating my quotes. There s so I'm going to give this a value of B. I'm going to give us a value of a and variable a invariable B s. So there is a difference in the way that content gets handled depending on the quotes. And I'll just show you a quick example of that by rearranging my order of variables here. And what I'm gonna do is I'm gonna include that value in here, So basically they're gonna look the same way, but one has a double quote. One has a single quote and I'm gonna just echo both of them out. So one line after another and I'm also gonna add in some HTML there for us a line break so we can differentiate the two strings. So let's quickly review before I show you the output here. Eso we've got was sitting a value for V A r of 200.10 to, and we can just disregard that That one s So we've got two different variables that we're sitting here and they're both gonna be string values. So one is a string value, and it's Botham are the same values. The only difference is that I've got double quotes on the 1st 1 So for a is double quotes and B is single quotes and notice here as well that I've contained that v a r in the middle of the string and I havent unquoted here. So I'm holding it within the middle of that string and interestingly here that Adam is smart enough actually to notice that there is a difference. So it's got one. That's kind of great out and then one that's the same color of the string values. And then I'm echoing them out here. So what do you think? The difference here is gonna be within the output. So I give you a second here and we'll go and refresh the page and notice how, interestingly, on the 1st 1 that we used double quotes where? Actually, we didn't have to break out of the quotes. And we can bring in that other value that other variable value that's contained within here . But on the single quote we actually brought in via our as a string value. So that was a little bit of a hint there from Adam as to what's gonna happen. And basically, when we're using single quotes than if we've got another variable here that's contained within that value, it's just gonna treat it as a string value. So it's going to just see it as dollar sign v a. R. As opposed to double quotes. It sees it as there's a variable value in there and simply picking up that variable value that's contained up there. So that's the big difference. Double quotes and single quotes. If you're not concerned about containing variables in there. There really isn't a whole lot of difference between the output of the strings. But if you are using variable values within the string quotes here, this saves you the trouble of actually having to to break the string. So this would be something where we could break out of the quotes there, and then we could continue and include that variable value. So in order to match them up, we'd have to do it in this type of format and then this would produce the same thing. So it saves us a little bit of work, makes it a little bit shorter and indicates that there is a difference between the different outputs there of the variables. So the next lesson we're gonna look at Aries sarees are just like variables, but they allow us to hold multiple values within that array or within that one variable value. And I'm gonna show you how to create a raise and output the content from the ARY in the upcoming lesson 12. 13 Working with Arrays PHP: in the previous lesson, We looked at just variables that hold a single value. And in this lesson, we're gonna look at a raise and a reraise. Give us the ability to hold what multiple values within that one variable assignment there and the way that we assign a rate. We do the same way that we set up a variable where we've got a dollar sign and then the name that we wanted to utilise for the variable or for the value. And then we equal it. So we assign an operator a sign of value to it. And then we indicate that this is an array. So we see array, and we do the curly bracket where the rounded Brockett and we treat the values in here just as we would any other variable. So it's open up her editor and take a closer look at this. So again, this is setting a variable called my array, and it can literally be whatever value or whatever name you want to call it. And then within that array so specified that we're creating an array and then we can add as many items as we want within this array and the format is gonna be the same thing as when we're setting up the variables and values individually. So if we've got a string here, we need to keep the quote surrounded. If we have an integer or a double, we don't need to quote around it and so on so we could have multiple values. Maybe this could be hello. And then the next one is world and so on. So this is essentially how we can set up an array. And now you're probably looking at this and saying, OK, well, now we've got this array and how we would How would we actually output that value so we could do something like my array the same way that we would be out putting the variable? But actually, this won't work because we're not specifying which item in the ri that we want it to special to pull out. So if we actually refresh this, it will see that we've got on air there and it says array to string conversion, and it just does not understand what we want to do. It doesn't make sense to output this array within this type of format, but before I go any further, there is actually a way to print out the values of an array. Eso, if you do are working with an array and you want to see what values and what contents are contained within the array, you can do function of PHP function, and this will actually print out the values of the ray. Just put their ray name in there, so print underscore are and I'll open up the browser, show you what that looks like. Eso Essentially, we get the re and its output within this type of format. Ah, and so this is another interesting part about ah, raise is that we've got an index value for each item and we see how that they're broken down by these index values, starting with zero. So all arrays start with zero. So even though there's four items in this array, the last item is gonna be index bracket three. And this is a good indication of how we can actually differentiate and pull these values out of the array by using these bracketed index numbers. Ah, and they're gonna correspond with the values that are signed to there. So it's gonna open up our editor. And because we're gonna be looking Teoh, pull out Maybe one of the values we can use Echo and again notice that we went all the way to We went all the way to three and notice I'm not using the rounded brackets. I'm using this square brackets here just like it is output here with the print R eso if we wanted to Maybe take item number two was the third item number two and we wanted to output that we could select it within this type of format. So there it is selected and maybe I should add in and to Can Katyn eat strings together? We're using a period That's the PHP syntax for that s o essentially just added in a new lines when they go to the source, we can see that that ray is output in this nice, neat form out here. And this is another way that we can specify and create their A by specifying these index numbers within this type of format as well. And it just simply outputs that content and were able to see that that value. So what do you think? How would we get world So how would we write out hello World without actually writing out hello world and utilizing the values within the strength. So how do you think the best way to do that? So we need to create a space there, and then lastly will include the item number three, which is the last item in the artery. And we just specify it in this type of format. Refresh it. And there we go. Hello. World pulled out of the race of one of the values there and the real advantage to these air raises once you start having a whole bunch of dynamic values, uh, having them all contained within one variable name allows you to kind of pull everything together and have it more related to one another. So if you're a Ray was maybe instead of an array, if it was a person and the person had a first name, so this would be first name and maybe this was the age of the person and then the last name eso on a last name wouldn't be last name and where they where they live. So maybe the city that they live in and so on. So you can see that there's more meaning and everything is contained within one slot, and then this way we can output it within a more meaningful fashion. And if we making any adjustments, if we're incremental in the age and so on and we can see that we can output that as well simply by calling those a re container values instead of actually calling out to those values. So I should make adjustments to this one as well. Eso you don't throw any errors there for missing those variable values and someone, and essentially, there's a lot you can do with a raise and PHP. There really, truly is just a ton of stuff that eyes involved in a raise. Ah, lot of built in functionality for a raise, and you can go over to PHP dot net and search it for a raise. And you can see you've got a ton of built in functionality that's ready to go with a raise s. We've got things like ability to sort it as this is probably one of the more simpler ones. So they give you an example here, and all it is is just simply utilizing the function sort eso just give you a quick example of that? So just do sort and then the array name and throw that in there and then we'll do is I'll print out that person again, go boat to local host and you can see that I should have ah, line break there. But maybe we can see it better within here. We can see that once we ran that sorting function that it actually sorted it, uh, Alfa numerically So starting with F L t and then numbers on. This is just one of the simple functions that's available within PHP for a raise. And you can see there's just a ton of other stuff here for a raise. So quite a lot of stuff to work with and a raise are a really powerful way to store data within PHP. So the next lesson we're gonna look at another common way to store content within PHP, and this is objects. And so this is going to get a little bit more complicated, and I'm gonna try to run through a really simple example of this in the upcoming lesson that's coming up 13. 15 PHP object quick overview: this example in this lesson, we're gonna be looking at objects in PHP now. Objects in Pete's P can get fairly complex. So I'm gonna be running through some of the rial bare bones, basics of an object, how they work, how they can contain some content and how he can output that content and utilize that object information within PHP. And as mentioned objects can get fairly complex. And within this example, we also have functions. So we're gonna be briefly introducing you to functions. And if you're not familiar with functions, we do have an upcoming lesson that is gonna look specifically at functions. So just it's important to know what that functions within this context are just gonna execute out, ah, line of code and is going to return it. So it's gonna be our way of specifying what part of the code we want to execute out. And we want to render that eight within the visible area of our PHP code. So that's what this court over here is going to be doing. And let's open up our editor and create our own version off a class. So the first thing that we do with the class. We define it by class and so that lets pukes be know that we're creating a class so we can call it whatever we want. So it is going to call it in the sake we're gonna call it class and we see that we're specify a class using the curly brackets and then within the class, I wanna have some values, some variables, and within classes were ableto have public and private classes. Eso with public. This is just a value that can be seen outside of the particular class. So it's used outside of the class, essentially. And so this is the one that we're gonna be using. We're gonna create a name and just write hello world in that name. So this is essentially a variable within the class containing the name or the value string value of hello world. And then next again, we want this public facing so the public to be able to access this So we're gonna do a public function and we'll call it so name and curly brackets again for contents within this function. So this is works, as typically a function would and were able to return some values. And because this value is sitting within the class, we access the class content by specifying this so we can specify this object contains the object value variable contained called name, and we want to just return that value. So essentially, what's happening here is that we're setting a variable name, uh, called hello world. And when this show name function is called, were returning that value from the above name and we're just simply returning up back that value. So this is a very simple cloths, and the functionality is really relatively using straightforward where were just returning back. The value is contained within name eso. Let's go down here and specify creating our object and specifying that we want to create a new instance of my class. So we specify the object name that we want to tie that to. So now o b j the value o p. J. Is gonna hold all of the properties of the instance of my class. So it's gonna be able Teoh echo out and return that value of name if we call for show name . So just to demo this, we're gonna echo dollar sign O B J and we're gonna call Teoh the object that's contained within their And we know that we set up one called show name. So we're going to simply echo that out and call that back from the newly created instance of the my class object. So let's check this out and see what it looks like within the browser through all of that work were rendering out hello world. And then if we look at the source, were rendering out hello world. So again, I know that classes can also get fairly complex s Oh, this is a very basic simplification of what you could do with classes. And I know probably in this example it doesn't make a whole lot of sense why you would go through all this trouble to just simply output Hello, world when we know that we could do echo Hello world. But the idea here is that you can contain a whole bunch of different functionality, have a whole bunch of different variables and values contained within this class. And the really good thing about using objects is you can really easily reproduce them. So if these values were dynamic and we're pulling in these values and still using set variables, and we're pulling in dynamic values. We had different values coming in for the class. Then you would see that there's a lot more return for all of this work that we're doing to set up the classes. So again, just a really brief. This is just really meant as a brief explanation that objects do exist in PHP, and this is a really simplified way of accessing objects and utilizing them within your coat. And if you're just starting out with PHP, you probably want to get more familiar with the fundamental concepts of PHP. So you want to get familiar with functions and variables before you go ahead and start setting up classes. Eso that's more advanced functionality and PHP and this lesson again. It's just a simplified, simplified summary of what objects are. So in the next lesson, we're gonna be diving deep into PHP and looking at additional values that we can set in PHP And these air called Constance. So they're not variables, but their constant and the idea for Constance are that they actually stay there, not going to be changing. So we define the value and we link of value to it. And then we call to that value. Eso Let's ah, let's jump into that in the upcoming lesson. 14. 17 PHP constants: this lesson, we're going to be defining constants. So constants are a way to hold and define ah, value that's not expected to change. So as opposed to variables and variables by nature, it's meant to very and change throughout the code. But when we define actual Constance than the idea is that they're not changing, So in this example, we're defining something called ad space. I've got some html attached to it, and then I can echo out those that constant value so they work the same way as a variable would work. But we don't have the ability or we shouldn't be updating them at any point. Eso In order to initiate it, we define it. We set a name for it. So an example would called ad space. So we call it ad space. And then within here is what whatever value string, each team melon, you want eso Maybe we're gonna also do the same thing as we have an example. So type in some html here, so I'm gonna single Quote that so I don't interfere with my with my quotes there with my double quotes and I'll just call it link. So now I know, whatever I call ad space, I can output that content so I can echo out the value of ad space, the constant ad space, and noticed that no dollar sign and by default, you don't have to use upper case, but usually were just using the upper case letters so that it stands out and were able to differentiate it. Let's take a look and see what happens here. So this just gives us ability to use a constant so a lot of times to you're going to use Constance. If you have a key that maybe you've got a key that you're accessing a p I with. So you want to find those keys or you want to find where your libraries air located or anything that you don't expect to change within your code. You would define it by ads by as Constance, and that's the basics of using constant. So you don't use them a lot, but they do have their purpose, especially. You've got larger applications and you're holding values and very values that you don't want changing eso the next lesson. We're gonna jump back into our variables and I'm gonna show you different operators that you can do with variables because, as mentioned variables are meant to change and there's a whole bunch of operators that allow you to do this really easily with PHP, so all of this is coming up. 15. 19 PHP Arithmetical Operators: It's a lot of different types of operators in PHP, and one of them are one set of them are the mathematical functions that are available in PHP. So let's take a closer look at thes within our editor and will set some values. So set a value of variable A and we're going to give it a value of five. Will give B and we'll get a value of 20. And now we're setting, see, so we can assign a value of a plus B so we could make a little bit door dynamic, especially when these values are changing throughout our script. This provides a whole lot of functionality really easy to implement within our code. Eso Now, when we electrical out, see, what do you think of the value of sea will be So what do you think you're going to see in our output here? And if you said 25 you are correct that we actually took the value of A and put it here we added it to value of B and then we got an output for C. So as mentioned within example, we can subtract, we can multiply, weaken, divide as well So if we hade, maybe this makes more sense. B minus A. So we have changed that to a minus sign. And what do you think C is gonna be? 15 eso were minus saying we're doing 20 minus five. So we're getting 15. We can do a multiplication. They're so 20 times 5 100 we can do division. So 20 divided by five is four and so on. And of course, you can make even more complex formulas so you could do something like plus B on or times a and so on. So as we make thes more dynamic, we can create all kinds of amazing, really cool values and the mathematical rules apply. So whatever's within the brackets is first eso if we have something like this weaken bracket at first, Actually, that didn't change anything, but we could do something like divided by a and so on eso we could make more complex formulas and keep going with all of this different. Different operators are available in PHP, and we've also got what's called assignment operators on this is again what really makes it easy toe work with variables in PHP. So we'll take a quick look at those in the upcoming lesson 16. 20 PHP Assignment Operators: this lesson. We're gonna look at assignment operators and PHP. Essentially, what an assignment operator does is that it sets a value in PHP. And we've already been using ah, whole bunch of assignment value variables, values operators. When we do something like a equals five and we do B equals 25. So these are all assignment operators, just the equal sign s let's do see and with see, we're going to switch it up a bit. So we've got ability to do a plus equal So adds a new value to the first value eso We should have some kind of value for C. So if we did something like a plus equals and we just give it a number there, So a plus So this will be a clip into saying Maybe I just write that. So a equals a plus one. So that's the same thing as saying equals a plus one. It's gonna return that same value. So when we echo out A, it'll be six. And actually, in this case it will be seven because we're adding one over there as well. So let's see what the output there is. So it is seven because we're doing a equals A plus one twice. We're adding one to it twice. We could also do. We can also subtract from the values we could do. See equals plus and maybe minus four. Eso show you what happens here. We're not actually defining a value for C. So do you think that this will work if we haven't actually to find anything for C and notice that we've got an undefined variable? So we have to always use the assignment operator first, where we have to assign a value. Foresee eso We can't just jump into thes ones. We can't do the short form assignment value variables, operators to the variables we have Teoh always a sign of value to at first eso. Now, when I refresh it so that will work and that will provide us a value of negative for because we're starting were defining See to contain a value of four. So always before you use thes short hands, make sure that you're doing that assignment operator there. So next we're gonna look at some conditional statements and these air really great for PHP and writing code because this gives you more power to actually ask a question in regards to the value that's contained within the variable, so that's coming up in the next lesson. 17. 22 PHP conditional statements: conditional statements are one of the core fundamental principles off writing code. It gives you the ability to essentially ask a question and provide a result So you can see here that we're gonna look at if else statements. So essentially we've got if a is there. So if a is true, then we'll see that ec a has a value and so on. So we're gonna open up our editor and I'll write some code here. So we're going to give a value of Let's give it a value of truth, and our first condition will be if a and then we're gonna echo out a exists and we can even throw in the value of a there and swells. Remember, we're doing the double quotes there, so we're have that ability. So let's see what happens here when I refresh it a exists. So what happens if I do false. So this condition is no longer met and we don't get anything being output within our visible area of our code. So this leads us to the next statement that we also have the ability to check if something is true, and then I would put something if it actually doesn't meet any of the conditions that we're looking for. So let's ah, let's duplicate this one out. And we're going to write if a and where you keep that same one and we're gonna include else . So this else statement gives us the ability to actually take some kind of action in case it does not exist. So not there. And now, if a is false, it's gonna actually output something. So simply outputs not there. If I change it over to true, then we're going to meet both of those conditions, and we're actually going to see it out. Quite so a exists exists eso what happens if you've got another condition that you want to check? So maybe you want check if a is there, and if a isn't there that we're checking B is there, and then if a and B are not there than we'll just put a value of not there, So get rid of thoughts and we're just not there. And so in here, we're gonna odd else. If so, this is just another condition, and we need to actually specify just as over here we've specified that if the else if it works the same way where we need to specify what needs to be met. So just do a quick check and see if B is there. And if b exists, then it a lot put the value of B and I should be. So just make a quick update there. So when I refresh it so a exists exists maybe a comment that one out and we just do Ah, false there. And now So a doesn't exist but be exists, so we get a value of 100. So what happens if B is non existent? Or if it's Cyril? So do you think we still output B s O? This just shows that zero false? No, they're all equivalent to, uh, the condition not being met. So if we've got a value of zero, then be actually doesn't exist because zero is zero and there's no value contained within their So will receive that else if b is zero. So this is one thing Teoh watch out for. And if we entirely remove, it would be. Then we're still looking for the variable B, and we're gonna throw an error there. So you got to be mindful of the fact that we're looking for that these variables need to be declared before we try to look for them and before we try to access them. So just keep that in mind and used these statements. Keep be mindful of the fact that zero is equivalent to false or not. They're eso it'll when we're doing the conditional statements, zero will be treated as not being there and nothing will show up. So just keep that in mind when you're working through the different, different conditional statements. So besides a conditional statement, if you've got a whole bunch of cases, you might not want to do a whole bunch of else if else if else if and you might want a instead use what's called a switch statement, so that's coming up in the next lesson. 18. 23 PHP switch Statements: this lesson. We're gonna look at switch statements in PHP and switch statements. Give us stability. Teoh expand on what we're looking at in last lesson where we had a condition and if the condition was met, we could have some type of output. Well, a switch statement works in a similar fashion, but it actually looks for the particular value here. And that's what's known as the switch condition here. And once it checks to see if it's got a matching case. And if it does have a match in case it renders out the code that's set within that matching case and then notice between the different codes. We always have a break because this gives us the ability to actually break out of that code . So it's open up her editor, and we're going to set a quick variable here so variable for a and we'll give. Give it a value off test so it could be a very able that can be on Inter Jer. It could be a string or can be an integer eso, depending on what you want to match the case to eso we're doing switch and we just specify the variable that we wanna make the take a look at and match the case with, and then we go through and we do case eso because this is a string value. So we need to match that case accordingly. Do the colon there in order to match that case. And then from here is where we could echo something out, value found. And then what we're gonna do, just do the break here. And it's always a good idea to include a default. So let's say, for instance, this case is not found. We might want a default a default case to show up. So in that case, we can just do not there and we don't need to break because this is our last one. Let's go take a look and see how that renders it. So the value is found. So if I changed tests to test five, we'll see that we get not there being rendered out. And I guess I this really does gives us a really good capability of having a bunch of different cases there and doing a bunch of tests s. We could have test one and we could have test two, and so on, so just aligning that better. And until we actually hit that the tests that we want to utilize or the value that we want to utilize. In this case it's test five. So found value found one you found, too, so that we have something different happening here. Three and four. Let's go take a look. And what you think that put is gonna be value found? Number four. Essentially, that's how you use switch statements in PHP. And in the next lesson, we're look at a logical operators. So these come into play, especially for doing these conditional statements. They give us a little bit more power on the conditions and giving us the ability to kind of take a look through and match some additional conditions as well within that initial statement. So you take a look at those in the upcoming lesson 19. 25 PHP Logical Operators: in this lesson. Let's look at some logical operators in as mentioned. They give us a little bit more power with our conditional statements. Open up our editor and take a quick look and see how logical operators can work in a conditional statement. So before we had our conditional statements, so we had, if a and then if that's true, then we echo out it's there and close that off. So with the logical operators, we can do some additional logic playing additional logic to it where we could do something like. And so this would make sure and check if A and B are there. And if that's true, then you'll see it's there or should say they are there. And if maybe we set the value to be 20 so do you think that that's still gonna be true? And it's not so we should also add in our else there s o maybe we just put not true. So if a and B, then they air their else Not true eso We did have another logical operator we could do, or so we can switch this up and do just the lines. There s this is the same thing as writing or so now it's actually there. And what war is doing is essentially saying, if a is there or if B is there than it does the true statement and else it does the not true statement eso That's the big difference there. We can also do a not true. So if if something like if b is not there than it'll right there, there s Oh, this is the not true statement and we can also do them as and us. It's refresh that's so not true. And now it's given a value there. So if a and B they are, they're so this is the same thing as writing the and A and B they are They're not true and so on that so the logical operators work in PHP. That's how logical operators work within PHP. And in the next lesson, we're gonna be looking at comparison operators and how they work and operate within PHP. And this is going to give you even more power in your conditional statements that's coming up in the next lesson. 20. 26 PHP ternary operator: finishing up on operators. We're gonna look at conditional operators really quickly within this lesson. Now, conditional operators could be really useful because they actually simplify that conditioning process by really simplifying those values. So over here we've got a value of a equals to 10 and then we've got B and it's equal Teoh, and it's got a whole bunch of values. They're attached to that. Let's take a closer look at this. Open up our editor. So we're going to set a value of 10 for A and for B. We're actually going to do something different. So we've got B and we're sitting be equal to, and we're gonna have the rounded brackets and we're gonna check to see if a so we're gonna match. We're gonna get create value of B, depending on what the value of a is. So if a is greater than or equal to 25 then we're gonna ply the condition of So this is setting a value for B. Yes, it's greater and even odd in that value of a and then if this is not true, so the 1st 1 here means this gets set for B. If a is greater than or equal to 25 b will have a value of yes, it's greater than and showing the value of a And if not then no, it's not. And we'll also may be specified the value of a in here and close that off by semi colon. And finally, let's echo out be so we get a value of No, it's not 10 eso when a is greater than or equal to 25 eso it's not. But if we increase the value of a to 100 then we can see that yes, it's greater than 10. So essentially, this saves you quite a bit of time on the conditional statement here where we would have to do if and then do this condition and then if the condition was true, then be would be equal to Yes, it's greater than else. No, it's not. And so on. That saves you quite a few lines of code and really simplifies this. This is also sometimes known as the Terran Eri operator s Oh, that's t e r and A are why operators so sometimes also known as the PHP turning your operator. So just gonna write that down eso different names for it. Sometimes it's also called conditional operator and so on and basically simplifies the output. Eso you've got your condition here, and if it's valid, then you've got this. And if it's not valid, then you've got that value coming out. Eso the next lesson. We're gonna also look at string operators how we can come to Captain eight strings and add them together and then the short form for that so it's coming up in the next lesson. 21. 27 PHP String Operators: in this lesson, we're gonna work with string operators and what stream operators do is they give us the ability to concoct innate strings together so essentially joining them together just like in this example. So let's start out with giving it hello and B will be world. So I've got two strings. We want to join them together in C So let's do that where we've got a and we've got B and joining them together and echo out. See, let's take a look within our browser. We've got hello world there. And of course, if you want to add in a space, we need to add that in as well. And we noticed that there's also a way to add it together so we can simply add a and B together and contaminated with C. So if already have a value for C, and we do something like C equals do dot equals. And let's just add this one together with that now. So what do you think the output of see? What do you think the last and final value of C is gonna be? Let's take a look in the browsers we've got. Hello world. Hello. world because essentially what we're doing is we're adding them together. So I'm gonna just add in some html there and a space. So I got hello world and hello world. So now see, actually contains both of those because we're setting the value of sea there. And here we're can count mating the value of C, which was already a plus B. And we're adding an A plus B to it again. And that's where we've got hello world being output twice and essentially that's string operators and joining them together and this is a shorthand format of joining come together . So the next lesson we're gonna bring a lot of this together that conditions, the increments, the echoing out and a whole lot more. And we're gonna be looking at loops and loops are a great way to I would put content repetitive, Lee and over and over again, without actually having to write it over and over again. So that's coming up in the next lesson. 22. 29 PHP Loops: One of my favorite things about PHP and coding in general is applying a loops number of different ways to apply loops. You can do a while loop but do while loop and a four loop. So I'm gonna show you how they all work and how they all fit together with the conditional statements that we've been looking at earlier. So it's open up our editor here. And first of all, let's set a value for a legal A to five, and let's create another variable. And maybe this variable can contain some output. And in the initially, we're not gonna have it contain anything. So just be blank and then don't here, let's cycle out. Put So what happens if I wanna have Or maybe we're going to start a out with a value off one, and what I want toe happen is I want a two continues the increment, and I want out. Put it and eso on. So add to the output value and then finally put it all out within this eco statement so I could do something where I've got output and I can continuously add toe output and uh, is now and then have the value of a and so on and over here I could increment a so I could do something where I'm adding to a and so on. So what happens now is I've got a is now too. So I don't want to keep rewriting this over and over again. I want essentially apply something where I've got while a is less than 10. So maybe I wanna output it 10 times and I want to have this loop happening here. So this is the while loop and I'm gonna put this increment here afterwards. Eso Now let's see what happens when I refresh it. So I need to add in a space there. And this is the beauty of loops because this gives me the ability to really quickly update it. And because I'm using the double quote, I can do it this way. Eso let's see what this looks like now. So I've got a is now one a is now to a is now three. So all I'm doing is taking in that dynamic value of a and I'm out putting it and I'm leading the loop. Take care off all the magic and simply out putting it. So that's one way to do the loop eso There's actually several different loops that they did mention, and depending on the condition and you're coding what you're trying to accomplish, you could use either one of them again, depending on the scenario and whichever one makes sense. So we've got another loop which is called a Do loop us. We can actually do something relatively similar where we've got this output and then we're gonna increment a. So always remember that when you're doing loops, you need a way out of that loop. So if I don't have that, a incremental ing a will never actually reach above 10. And this loop will go on indefinitely because A is never gonna be increasing. And either way, that's going to create a huge problem. So same thing for the do loop. We need to make sure we have a way out of it. And that's where we need to add in that while condition. And here we're just say that while A is less than 20 because I know looking up here, we're actually already implementing a to 20 or were implementing it to 10. So we're going to do another increment of 10 on a and just show you what happens now. So essentially that do loop is continuing. The work output is relatively similar, just in a different format. All of the same conditions are being met. And then lastly, we've got the four loop. So we're going to do something very similar again where we've got our four conditions there and then what we want to happen as we're out putting. And usually I find that the four loops look that need us to me and again. It's essentially all of the same things that we had in the other loops where we've got initial value for a we've got our conditioned for a So this is the next, the next value that we're putting in there. So condition for a notice that we're separating with the semi colon. And then lastly, we need to increment a so that we can break out of that loop, go back out and let's refresh it. And there we see we've got the four loop, so starting at one because one is the default value and we're going to continue this while it's less than 10 notice. That's not equal to 10. So that means that our loop ends at night. So just as this loop ended at nine, this loop ended at 19. Because we're doing less than and we're not doing the equal. Then sign. We could always include that so we could have less than or equal to or whatever condition we want met. Just always remember that we need to have a way that the loops are incremental. These are very important to the loops, and having a good functioning loop is essential. Otherwise, your code will essentially go on forever. So those are the three core ways of doing loops. And again, I said, my preferred way usually is to do the four loop. But again, depending on what type of conditions and what kind of dynamics you have within your code, you might choose one of the other ones that might be more suitable for the content that you're trying to output. So the next lesson we're gonna look at functions and functions are another core integral part of understanding PHP. So starting to program with PHP functions are the last piece in the core functionality. In order to learn programming and getting to know functions is going to really simplify your courting, so that's all coming up in the next lesson. 23. 31 PHP functions: in this lesson, we're gonna be looking at functions within PHP. Now, understanding functions is important to understanding the basics of coding in PHP because you're gonna be using functions. Ah, whole lot within your coding. And as your coating becomes bigger and more complex, you're gonna be really happy that you're implemented functions because it's gonna make things a whole lot easier. So essentially, what a function does is it allows us to run Ah, certain snippet of code simply by calling over to the function name. So the idea here is that we set ah, function name by indicating function, giving it a name. And if we're passing some arguments which we are gonna talk about later on in this lesson as well, so passing over an argument and then doing something, returning some code and maybe doing some calculations, calculations and so on within your function. So it's open up her editor and create ah function. So functions are really simple to set up. All we need to do is specify function, and so that PHP knows that we're creating a function. Ah, and then give it a name. So we're just gonna call it my function or let's call it my fund. So right now, we're not passing any arguments, and maybe we're just doing some kind of calculation. So I'm gonna set a value for a of five. And every time this function is called, so a is gonna increment and it's also going to echo out, And then in order to call the function all we need to dio anywhere within our code, we just specify the function name within this type of format. So I got to do it three times and let's see what our output iss. So let's take a look at this error message, and we've got undefined variable a in line for and it's still out putting the one. So what's happening here is that it's coming to my fun. A is incremental in by one, but it's saying that we've got an undefined variable and we're out putting a and essentially, uh, we're getting that value off one, and it's out putting. And every time we're running my function, A seems to be resetting. So let's do something a little bit different where we're gonna pass that value of a and then we're gonna pick that up as an argument here, so that should just be a And now let's take a look at what happens now. So now we've defined that variable. But we see it's not actually incremental from what our value here is. It's not function exactly like a loop would where we had all these increments and so on because we're not tying it to the global variable. And this is where scope comes in. So things outside of the function are part of the global scope and things contained within the function. It's got its own set of variables and values, and this is its local school. So that's the big difference. And that's what happens within PHP when we try to call for functions and values that are outside of the school. Eso let's side do something a little bit different here where we've got a value of five. We've got a value of seven and we've got a value of nine, and we don't actually need this value anymore. Eso Let's focus in more on the functions, and we see what's happening now is that we're getting this dynamic output dynamic output off the script that's being run within the function So what we're doing here is we're passing over an argument. So this, for this line of code function, has ah value of five. It picks up the argument value of five, assigns it to a A increments by one and were echoing out that value. And that's what essentially the function step out of court is doing within the function. A lot of times, you don't want to necessarily be out putting any kind of cold within the function. Sometimes it can get a little bit messy. So for the most part, you probably just want to be dealing with variables and values. So let's ah, let's take a look at a different way of out putting this content so starting out by output and so just call it my variables, put a line break there, and now what we're gonna do is we're gonna do output and we're gonna add output, contaminate more output and have the function and do the same there, do the same there and then lost. Lee will echo out whatever is contained within output and one more adjustment over here. So we need to return a different value for a so so take a look and see what happens now. So I've got my variables, Will not spelt right. But sorry. No, it is spelt right. Eso my variables and we've got them running a function. So we're starting out, setting out output with my variables there as the value and then were running functions passing an argument, passing a value for a A is incremental ing and returning those brand new values that are being assigned to a every time the function is run. So you're probably looking at this and saying Okay, well, wouldn't it be great if I could actually use a value that's outside of the scope? So let's try this again. But we're gonna format something a little bit different, So giving be a value of maybe give it a value of five. I want to actually pull that value in, and I want to multiply a times B and return that value here within our output. So let's see what happens again now. So no, we've tried this before and again, we're having a problem there with the variable B. So we have actually away Teoh, bring in that global value into the function and we can do that by specifying global and specifying the global variable name. So if we do global be, let's try this again and we see that it actually works. So what's happening here is that we're defining that we want to use the global value of B. So now it's able to recognize it. Looks outside of the local values, looks outside of the function for a variable with a value of B, and then it pulls out in because we specify that global be so tying all of them together and then we can utilize it within our function and make our dynamic caught calculations which all of these values and variables can be changing at any time. So if we do something like be and maybe we want to add to be or something like that. So let's take a look at this now and we see that the value of B is changing and we're getting even, even mawr updates and values to that so we can update it, increment it again and again. We've got a different outcome there, so we can literally we can use the global values. We can interact with them, send them over the functions and have interactions within the functions of those global variables and then have some dynamic outputs and all in all have a lot of fun with functions. So functions are super powerful. There's a lot of different ways to use them. We we noticed that we didn't necessarily need to return a value. But a lot of times with functions, the computations that you're doing, you might want to return something out of these calculations on again. As I said, you don't necessarily want to have this output, uh, this echoing out of output within the function. Um, because sometimes that does lead to some confusion about the output. So if you are out putting those values, then maybe echo out fund five or something like that, which makes a lot more sense when you're echoing that it so again, echoing that out. And then we run the function, makes all the calculations for output and finally, output the value of output into the Web browser. And also, I just wanted to note as well that these don't necessarily need to be actual. They can actually maybe even be strings if you want, so this could be Hello or something like that. And then the next one can be world. And then the last one might not need to be anything. Eso let's add in another value another argument here within our arguments and and in order to pick that up here. So just two comma see? And here we're gonna output that and notice that over here we're not passing that argument . So let's see what happens. Refresh it. Got a bunch of warning messages. Ono means that we're not passing that argument. So we have a choice. We can either enter an argument there or we can set a default. So if nothing is picked up there for see, we can set it as a default of none. So that will do so. Refreshing it. So the 1st 1 didn't pass second argument, so we defaulted to none. This one again, didn't have a second argument, so defaulted to none. The other two had arguments, so they just took the argument values that were being passed in. So notice that we can pass multiple arguments. We can grab those global that variables. We can mix them all together and return some dynamic outputs within functions and We can really usually do this by calling out to all of these functions. And essentially, that's how functions work and very useful part of PHP coding. 24. 33 PHP conclusion: within this course, I've given you a quick overview of some of the basic functionality of PHP. And of course, there's a whole lot more to PHP than what's been covered within this course. It was designed as an introductory course to learning to code PHP. And I do promise you that if you learn the basics, then it will give you the solid foundation. Solid groundwork to start building some simple applications using PHP. And it's gonna be something that's gonna open up the doors to even greater things with PHP . And remember again that at PHP dot net. There's a lot of great documentation. There's help, forums and users and a whole lot of really good information as well as online. There's a ton of great information with PHP, so it's a great It's a great coding language to get started with very flexible, very forgiving within the coding and the syntax and a whole lot more So. PHP has a lot of benefits, and I hope I've covered all of the basics and got you interested into learning more about PHP. And again remember that practicing PHP is the best way to learn PHP. So I've included all the source code within the lessons, and I do encourage you to use application like Samp. If you don't already have a way to practice PHP, it's usually the best way to get started where you can open up an editor and render out your code from the editor directly into the browser and make updates to your code. See the changes, makesem or additional updates and really get familiar with the basic functionality that we've gone through within this course and again, this is the basic functionality, but it is a great starting point. It will give you the foundation that you need in order to build up and learn even more about PHP. So get familiar with variables, loops, conditions, functions, and this will set the groundwork Teoh greater things with PHP, and you can build a whole lot of applications with just the simple basic language functionality that I'm showing you within the previous lessons. Also, all the source code is included, so try it out for yourself, practice it and see what you can do with PHP.