WEBVTT

00:00.380 --> 00:02.720
Next up, let's talk about the data types.

00:02.750 --> 00:05.000
Remember that all that you can see here.

00:05.000 --> 00:07.790
You can also download under this video.

00:07.820 --> 00:11.570
Let me zoom in a bit and start with the scalar types.

00:11.570 --> 00:12.890
The simple types.

00:12.890 --> 00:15.230
So that's an integer for example.

00:15.230 --> 00:22.820
So the whole numbers the floats for floating point numbers strings and booleans which basically hold

00:22.820 --> 00:24.980
a true or false value.

00:25.010 --> 00:27.980
Then we've got the compound types.

00:27.980 --> 00:30.830
This would be an array and object.

00:30.920 --> 00:36.140
So with arrays we've got indexed arrays where you just have items in the array.

00:36.140 --> 00:41.690
And there are indexed with the next numbers starting always with zero.

00:41.690 --> 00:48.710
And then there is an associative array where under a specific key you've got some value.

00:48.740 --> 00:52.610
This is similar to map types in other languages.

00:52.640 --> 00:59.930
You can also have nested arrays which is a multi-dimensional array, which means that you can have an

00:59.930 --> 01:01.940
array inside an array.

01:03.170 --> 01:09.050
So PHP also supports objects which are created based on classes.

01:09.050 --> 01:12.860
We're going to cover objects in depth later on.

01:13.700 --> 01:20.450
Next up you should know about special types in PHP like null, which just means an empty value.

01:20.450 --> 01:27.380
And this null is same like in other programming languages like JavaScript for example.

01:27.410 --> 01:33.110
Then there is the resource type, which is often something returned when you work with files.

01:33.140 --> 01:39.440
Next up, let's read a little about the behavior of types in PHP.

01:39.440 --> 01:43.550
So you should know that there is something called implicit types.

01:43.550 --> 01:50.990
So if you define a variable, you don't explicitly have to define, or you can't even define the type

01:50.990 --> 01:54.350
of this variable, it is implicitly assumed.

01:54.380 --> 02:00.890
Now, I'm not saying there is no way to define explicit types in PHP, because there is a way and you

02:00.890 --> 02:03.830
can add explicit types to function arguments.

02:03.860 --> 02:06.140
Return types and class fields.

02:06.140 --> 02:12.470
But we're going to only learn about those later on, so I just leave it for later.

02:12.470 --> 02:17.720
So if you use variables then they are typed implicitly.

02:17.720 --> 02:21.230
In this case A would just be an integer.

02:21.260 --> 02:23.600
But you can cast types.

02:23.600 --> 02:28.070
So you can cast this a variable which in this case has a value of.

02:28.070 --> 02:30.160
Well that depends how you read that.

02:30.190 --> 02:38.800
You can read this as 55, but this can also be read as character five, followed by character five.

02:38.800 --> 02:43.000
And if you use the casting operator to integer.

02:43.030 --> 02:45.790
Every type has its own casting operator.

02:45.820 --> 02:48.460
This would be converted to an integer.

02:48.460 --> 02:51.700
In this case this would result in 55.

02:51.730 --> 02:58.930
Next up you should know about the type coercion, which is automatic casting to another type.

02:58.930 --> 03:04.300
So if you would like to compare the string five with a number five.

03:04.300 --> 03:13.000
So two values or two expressions that are of different type and you use the comparison operator for

03:13.030 --> 03:22.150
that, then five as a string would be implicitly casted to integer just for this comparison to be run.

03:22.300 --> 03:30.880
Next up there is strict and weak typing, so we can add a declaration that would enforce the types more

03:30.880 --> 03:31.690
strictly.

03:31.690 --> 03:33.280
That's for later.

03:33.280 --> 03:41.110
And as I've said previously, you can also in certain cases define the explicit types like for example,

03:41.110 --> 03:43.720
function arguments can be typed.
