‫All right.
‫So in the last video we looked at variables.
‫And now I want to talk about data types of the values that we store in variables.
‫And before we get into the actual types I just want to mention that PHP is a loosely typed language.
‫That means that when we define our variables, we don't have to define a type, right?
‫We say name equals John.
‫We don't have to say name colon string equals John because in some languages such as C, C plus, plus
‫Java, you do have to define the type of your variable.
‫And you can't put any other type in that variable.
‫But languages like PHP, Python, JavaScript, these are loosely typed languages as opposed to those
‫strictly strict type languages or strongly typed languages.
‫So I just wanted to mention that now, as far as the types go, we've already looked at a string, which
‫is a sequence, a sequence of characters.
‫It could be letters, numbers, symbols.
‫It just has to be enclosed in either single or double quotes.
‫Next we have integers which are whole numbers, and these can be positive or negative floats, which
‫are numbers that have a decimal point.
‫Booleans which are true or false.
‫Arrays hold multiple values.
‫Objects are collection of properties and methods, and I'll talk more about arrays and objects soon.
‫And then null represents a variable with no value.
‫And I know that sounds a little weird.
‫I think a good example, a nice simple example of that is if you have a variables for first name, middle
‫name, and last name, and let's say the person doesn't have a middle name, so you might put null for
‫that.
‫Just think of it as like empty or just just not there.
‫But it is in fact a variable and it's defined.
‫And there is another data type, kind of a special type called resource, which represents an external
‫resource.
‫And that could be many different things.
‫A file is an example of one.
‫All right.
‫So let's jump into our code here.
‫And I just have an empty index.php.
‫We don't need any HTML or anything for this.
‫We'll put in our opening tag.
‫And we're just going to look at each type.
‫I'm going to assign a variable to each type.
‫So we'll start off with a string even though we've already done this.
‫But let's set name.
‫So I'm going to set name to Brad Traversi.
‫And I used a single quote here.
‫But I can use double quotes.
‫So to show you that I'll say John, I'm going to say name to and set that to double quote John Doe.
‫All right.
‫So those are two strings.
‫And there is a difference between single and double quotes in certain things you can do.
‫And I'll get into that soon.
‫Now of course we can echo out the value of of these variables.
‫But sometimes you want to know a little bit more.
‫For instance, you might want to know the type of the variable could have been set somewhere else.
‫And you want to know the type or the length.
‫So you can do that with var dump.
‫So var underscore dump which is an internal function which will if I hover over this should tell us
‫it dumps information about a variable.
‫So let's pass in name into var dump.
‫And we'll come over here.
‫And you can see.
‫Let me just make this a little bigger.
‫We get the value Brad Travis.
‫But we also get the type which is a string.
‫We also get the length of 13.
‫So this can be very helpful.
‫VAR dump especially when you're dealing with arrays and objects which we'll get into soon.
‫We'll be using this for debugging throughout the course.
‫Now there is another another function that I want to show you and that's get type.
‫So with this you do have to echo it out.
‫It doesn't it doesn't print it by default.
‫And it's also CamelCase which is a little weird because most of Php's functions are underscore or snakecase.
‫So for this we're going to pass in name two.
‫And if we run that.
‫It's going to be on the same line because we didn't put a line break or a new line, but you can see
‫it gives us string.
‫So that's another way that you can get the type.
‫But I'm going to just get rid of that.
‫And I'm actually going to echo out a line break just to kind of separate things.
‫All right now and I'll do this in a different way later on.
‫Whatever I want to print to the screen, I'll just put in a variable called output.
‫That way we don't have to put a bunch of line breaks, but we'll just do this for now.
‫So that's a string.
‫Next is an integer.
‫So again an integer is going to be a whole number which can be either positive or negative.
‫So if we say age equals 35 we don't put quotes around it.
‫As soon as I put quotes around it it's a string right.
‫That's a string.
‫In fact we'll do a var dump.
‫Let's say var dump of age.
‫And if we reload that, you can see string length is two and the value is 35.
‫If I take the quotes off and then save and reload, now I get int.
‫So int and I get the value of 35.
‫And I could make this a negative as well.
‫So if I do negative that's still going to be an integer or an int of -35.
‫All right so that's that.
‫Next we have a float.
‫So let's echo a line break and let's say float.
‫So a float is a decimal.
‫So maybe we have a rating.
‫We'll say rating equals 4.5.
‫Again no quotes.
‫As soon as you put it in quotes it's going to be a string.
‫So we'll say var dump and pass in rating.
‫And if we take a look, we get float.
‫If I take off that 0.5, then it's going to cast to an integer.
‫So that's what I mean about loosely typed.
‫We don't have to do like rating float or something like that.
‫All right.
‫And let's echo out I'm just going to keep this in my clipboard.
‫Okay.
‫Next we have a boolean.
‫So a boolean has to be either true or false.
‫So let's create a variable we'll say is loaded and set that to true.
‫Again no quotes.
‫And then we'll do a var dump.
‫Of.
‫Is loaded.
‫And we get a bull.
‫Okay.
‫Next we have an array which is a variable that can hold multiple values.
‫So let's say we have an array called friends.
‫We set an array with brackets and we're going to have an entire section on arrays.
‫So if this is confusing, don't worry about it.
‫But this can hold multiple values and it could be different types too.
‫So if I put a string in here John.
‫Jack.
‫Another string.
‫Jane.
‫So I have an array with three values, and I'm going to do a var dump of friends.
‫And let's check that out.
‫And we get an array and it shows us all the values along with the type along with the length.
‫And each array has an index that starts at zero.
‫So this is zero.
‫So you can see zero points to a string of John.
‫This is one.
‫So this one points to a string of Jack and then two points to a string of Jane.
‫Okay.
‫And then let's just put a line break there.
‫Next we have an object.
‫Now objects are a little complicated if you're just getting started.
‫So don't worry about this too much.
‫But objects are created from a class.
‫So I'm going to say person and set it to new and then STD class.
‫I know that's not the best naming convention.
‫And then we can do a var dump.
‫Of person.
‫And if we take a look here, we get object and it shows us the class that it belongs to.
‫Okay.
‫And again we'll get more into that later.
‫So next we have null which basically means that there's just no value.
‫So let's say that maybe we have variables that pertain to a person, name, age and so on.
‫Maybe car like the type of car they have is a variable, but they don't have a car.
‫So we'll set that to null.
‫And then if we do a var dump.
‫Of car.
‫We should see null.
‫Now, the last one that I want to show you is a resource.
‫Now, a resource can be many different things.
‫I think a good example is is a file.
‫So if we want to let's say I'm just going to temporarily create this sample dot txt file.
‫If I want to access that from within PHP, I can and I'm going to get into that later on.
‫The purpose of this is just to show you what a resource type is.
‫So I can create a variable called file and then set it to F open, which is a PHP function that will,
‫as you can see, open a file URL.
‫So it basically creates like a handler for us to do things with that file.
‫So we can pass in let's say sample dot txt.
‫And we'll say we want to read from that file.
‫So we'll pass in another argument of R.
‫And then we'll do a var dump of file.
‫And we should get resource.
‫Yeah.
‫So we get resource of type stream.
‫Okay.
‫So I'm just going to delete that.
‫I'm not going to have that in the in the final code.
‫If I reload now you'll see I'm going to it's going to tell me that it failed to open that stream or
‫that file.
‫So I'm just going to comment that out.
‫Okay, so those are the main eight types in PHP.
‫In the next video I want to talk a little bit more about strings, because obviously strings are probably
‫the most common data type we'll be working with.
‫And we're going to look at something called concatenation.
‫And also see what the difference is between using single quotes and double quotes.