Placeholder Image

字幕列表 影片播放

  • So how do you set variables and PHP?

  • The first thing to remember when you're creating variables and PHP is that you do not have to declare what they are.

  • You don't have to declare them as an end as a Ciara's a string as a float as a bull or anything else, you can simply create the variable and then set it to whatever value you want.

  • So this could be very nice, because it makes creating variables and PHP easy.

  • The problem is, is yet you can run into some weird issues if you try to do things such as, uh, adding a string into a variable, that should simply be an integer.

  • So this is just something to keep in mind whenever you're dealing with variables and PHP is that you don't have to declare what they are.

  • That can be a good or a bad thing, depending on what you're doing and what your skill level is.

  • Now, when you create a variable in PHP, the first thing is that you're going to have to start with a dollar sign just because all variables and PHP starts with dollar signs.

  • That's just how it is and then pass that you can name your variable Maur less whatever you want to name it.

  • But do you realize that capitalization matters?

  • So dollar side int i nt and all lower case will be one variable dollar sign int all in uppercase i nt all in upper case would be a different variable.

  • So do you remember that to use the dollar sign and to use the capitalization correctly Beyond that, there's really not much to it.

  • So all you do is you would do dollar sign into equals one semi colon and you have now created the variable ent and you have said it to a value of one.

  • So with that, let's go over to the computer so he can give you a demonstration of how this works.

  • So this is a basic script that have titled variables that PHP.

  • And what this will do is this will create a string variable for us.

  • This will create an inter variable for us, and this will create a float variable for us.

  • And then all we're going to do is we're going to print out those variables just onto an HTML Web page.

  • So, of course, whenever you're going to be starting a PHP script.

  • The first thing is you have to to add the PHP tag.

  • So this calls PHP and then in order to create variables as I've said, it's very easy.

  • The first thing that you do is you add the dollar signs so you always start the variable with the dollar.

  • Stein.

  • Ah, and then you say whatever you want the variable name to be, then you do space than you do equal.

  • And then you set the variable tow whatever value.

  • Now, if you're going to be doing a strings, you're going to be saying hello, world.

  • You're going to be saying somebody's name like a first name or a last name.

  • Basically, if you're going, be printing out something that should be text.

  • What you're going to do is you're going to start with a double quotation mark.

  • You're then going to add whatever that string is supposed to be.

  • Then you close with a double quotation mark, and always remember the semicolon.

  • The semi colon is essentially the period in PHP.

  • So whenever you finish a line of something, whenever you finish a command of any sort, you should stop with a semi colon.

  • So here we are, creating a strength.

  • You are creating a variable with the name string and we're setting it to hello world.

  • Then what we're going to do is we're going to create a variable for ent for an integer, and we're going to set it to a value of one.

  • Then we're going to create a variable called float Dollar Sign float, and we're going to set it to a value of 2.2.

  • So again, notice here.

  • If you're used to using other programming languages and other programming languages, you would have to declare what the variable is.

  • You'd have to declare whether it's an end, whether it's afloat, whatever it is.

  • And then you could only put that data type into the variable.

  • Here, you simply create the variable, and then you dump in whatever value again.

  • This this makes programming PHP very easy for beginners.

  • Ah, but it also allows you to create a lot of problems if if you don't really think about what you're doing.

  • But we'll talk about that in another video.

  • So all we're doing at this point past this is we're just going to create an html page that's going to print out of the values of the variables that we've assigned.

  • That's what we're going to do here is we're going to use the print function and we're going to use the double quotation marks.

  • And then we're going to do H one h one tag and they were going to say String.

  • So what it's gonna do is it's going to say string and bold and then below that we're going to print.

  • And then we're simply going to print the value of strength.

  • Now realize there's no double quotation marks there.

  • There's a single quotation marks here.

  • If all you're going to be doing is printing out the value of the variable, all you do is you do print space and then what?

  • The variable issue.

  • Don't put any additional information there and then you're going to end with a semi colon.

  • Of course, then we're going to print.

  • We're going to do H one.

  • We're going to say what the intern into your variable is.

  • We're going to close that and they were going to do print, dollar, sign into and then semi Colon.

  • So this is going to get a title for ends, and then it's going to print out the value of that integer.

  • Then we're going to prints.

  • Same thing.

  • We're gonna do the same thing with float, and then we're going to print dollar sign, float semi colon.

  • And then, of course, always remember to close PHP.

  • If you don't close PHP, your PHP script won't work.

  • And so this is the entire script to create and set the string and and float variables and then print out the information.

  • Now if we go up to the website, so you go to silicon dodo dot com variables dot PHP right up at the 2nd may not be here later, but right now this is what the output of this particular script is, so we can see string and that's an H one and a string as hello world.

  • Then we can see ends and then we can see the value of the invariable is one.

  • Then we can see float, and the value of the float variable is 2.2.

  • So this shows you how to create a variable and PHP how to set the variable and then just simply how to print it out.

  • So you can see what value is in that variable when you're creating variables.

  • Just remember, you do always have to start with the dollar side.

  • The capitalization does matter.

  • So upper case is different than the lower case.

  • And then, if you're going to be doing a string, make sure to put the double quotation marks around it.

  • If you're simply going to be doing number values, you don't have to do that.

  • So that's really all there is to creating an setting.

  • Variables.

  • Make sure you start with a dollar sign.

  • Make sure to remember that capitalization matters than you do.

  • Space equals If it's a string, you the double quotation marks.

  • If it's not simply a number, you just plug in whatever number that is, And then away you go again.

  • You don't have to declare the variable, which makes it really easy to start programming for new people.

  • But it also makes it really easy for new programmers.

  • Makes really horrible code, but we'll show you some of those problems going into the future.

  • There is some more to know about variables as you go on, you start to do bigger projects, but this should give you a decent overview.

  • Now, to be clear, when you are naming your variables, there are some illegal character.

  • So if you want to do the dollar sign and then you do the variable name, there are some characters you can't use in order to start a variable.

  • If you want to know what those particular characters are, just do a simple Google search.

  • And I'll tell you the specific characters.

  • If you're doing normal things such as, you know, calling things by a name and string message, something like that, you should be fine if you start with basic letters.

  • But there are There are some illegal characters.

  • Just do a simple Google search if you start running into problems, so that's really all there is to creating and setting variables, and that's how you do it.

So how do you set variables and PHP?

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

A2 初級

PHP - 設置變量 (PHP - Setting Variables)

  • 7 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字