In this Article, we’re going to go over variables in PHP.

 now there are three basic types of variables string variables numeric variables and arrays.

 we will deal with strings and numbers in this Article arrays. we will talk about at a later time now the most important thing is in PHP.

 you must place a dollar symbol at the start of all your variable names.

there is a purpose behind this really and it makes it much faster for PHP to know that you are declaring a variable.

 so it enhances the general execution so by and by you need to put this before each variable that is not negotiable so this is our variable name right here.


 now you can enhance the general execution so by and by you need to put this before each variable.


 you can’t start your variable name with numbers so I can’t put a 1 here that’s not going to work you also cannot use hyphens so no hyphens are allowed.


you can, however, use underscores those are allowed you cannot use whitespace I can’t put any whitespace in the variable name it must be one constant arrangement of characters.


 now if you do want whitespace.


 I suggest you use an underscore in this place and obviously the greatest manage as I said before you require a dollar symbol at the beginning of every variable that you declare.


now there are a few decisions that are viewed as great coding practice in PHP.


the first is put all of your variables in lowercase do not mix and match your case keep them.


all in lowercase you can’t put them all in uppercase if you want but I wouldn’t recommend that I would keep them all in lowercase.if you use several words in your variable you should isolate them with an underscore so on the off chance stickers on the crates to recognize what’s inside them so the case would be the variable that I for example on the off chance that I spelled var out two variable I would probably put an underscore right there or in the event that you have three or four names in your variable that is fine yet simply isolate each word by underscore and that makes it much easier to read .


now as I said in the last Article this is an entire statement now the first part we declare the variable and we are just giving it a name in the second part we are allocating an incentive to this variable so think about a variable as a compartment.


 it just stores whatever data we want to hold to use later on we dole out qualities to the variable for this situation we are doling out this string an incentive to this variable once.


 we have the data stored in the variable we can use it over and over again that’s the great thing about variables.


 you don’t have to type out the information, again and again, you can simply reference the variable name.


since this s5et of characters in this string is now stored in this variable name and obviously, it is finished utilizing this equivalent sign so they give it something like boxes that you have at home you store things in those boxes and put stickers on the crates to recognize.


what’s inside them so the case would be the variable name that stores our string variable then when you come back later they are there and you know what’s inside them.


 now the quotation marks signify that this is a string which of course contains characters now what’s different here than from many other dialects is we don’t need to characterize.


 the datatype on the off chance that you took my Java C or you’ll remember you always had to define the datatype.


 but in PHP and similar to JavaScript really you don’t need to pronounce the information compose PHP will really do it for us automatically.


 when we set the value and it doesn’t because it understands these statements here will be a string datatype.


so PHP simply does it naturally for us so this variable again will hold a string and we can utilize it at a later time and we’re going to use it very quickly so in this case let’s go ahead and use it with echo so you can output this string variable to the browser so you will remember from the last Article.


 we just type in reverberate and afterward we can simply ahead and reference our variable name it’s that basic and after that recollect each announcement must be shut with a semicolon and so now this will yield the substance of this variable.


which obviously is this string so how about we simply ahead and spare this currently open up the program that you want to use in this case.


 I’m going to use Chrome you’ll see here I set a favorite to my localhost lesson dot.


 PHP so I no longer have to type this in you may want to do that too because we’re going to using this file over and over for a while so if I hit this there.


 you can see we got our output now as I said there are also number variables which can contain you guessed it numbers so we can store numbers which is very useful if we want to do math and all sorts of different things so let’s go ahead and rename our variable to something a little bit more relevant we’ll call it integer there and all you do is put in the number that you want so let’s put in 22 that’s what we’re using.


 now you’ll notice this time we don’t need the double quotes once PHP sees that this is a number.


 it knows that it’s an integer datatype and by the way, you can also put decimals here so if we wanted to make this 22.7.


you can do that but we’re just going to make this 22 and then we have to put our new variable name right here.


 so we’ll just call this integer very simple and let’s go ahead and save this and then we’ll rerun this in our browser and there you can see we got the output that we wanted 22.


 okay, that’s going to do it for this Article I will see you guys in the next Article…

Categories: PHP

Leave a Reply

Your email address will not be published. Required fields are marked *