WEBVTT 00:00:06.600 --> 00:00:16.510 More so now so you get to learn how to add an array inside an array. 00:00:16.910 --> 00:00:17.510 OK. 00:00:17.760 --> 00:00:23.860 So you're going to use a function we call a race place. 00:00:23.910 --> 00:00:30.360 This function is going to allow us to add any elements we want inside an array in a certain position 00:00:30.360 --> 00:00:30.380 . 00:00:30.390 --> 00:00:30.780 So 00:00:34.680 --> 00:00:39.450 the function is going to take a few promises so the first one is going to be the array in question it's 00:00:39.450 --> 00:00:40.500 going to be shopping baskets 00:00:43.320 --> 00:00:44.010 and 00:00:46.830 --> 00:00:52.320 then we're going to have a strong position. 00:00:54.990 --> 00:01:05.910 Let's go for zero for example and then we're going to specify how many items we want to delete from 00:01:05.910 --> 00:01:06.530 that position. 00:01:06.540 --> 00:01:10.340 So let's add that to two. 00:01:10.350 --> 00:01:11.850 OK. 00:01:12.890 --> 00:01:17.670 And finally let's have an array we want to insert. 00:01:17.760 --> 00:01:24.870 So we want to insets for example and an array with a couple of elements Mongo and Kuei 00:01:27.490 --> 00:01:39.940 paint and then we're going to print the shopping Muskie's again and see what the result is. 00:01:42.810 --> 00:01:44.250 OK so if you're approached a page 00:01:47.850 --> 00:01:54.850 with an error then we need to make penances. 00:01:54.900 --> 00:01:57.620 So if you press the page OK. 00:01:58.230 --> 00:01:58.740 So now 00:02:02.610 --> 00:02:12.670 our array is OK first of all just add a paragraph just before printing the array. 00:02:13.030 --> 00:02:16.870 That's it's more visible. 00:02:17.670 --> 00:02:22.890 Does it go shopping baskets. 00:02:25.410 --> 00:02:26.030 OK great. 00:02:26.100 --> 00:02:27.430 Let's refresh now. 00:02:27.840 --> 00:02:28.350 OK. 00:02:28.590 --> 00:02:33.630 So now our shopping basket as we see so what's happened is 00:02:39.000 --> 00:02:43.610 before that's ok we started from this. 00:02:43.620 --> 00:02:49.540 OK so this is the original value before we use the array splice function. 00:02:49.800 --> 00:02:53.400 OK let's add another paragraph just before this as well. 00:02:53.710 --> 00:02:55.410 It's more readable. 00:02:56.030 --> 00:02:58.780 OK. 00:03:00.890 --> 00:03:02.010 OK let's. 00:03:02.390 --> 00:03:06.120 OK so before using the array splice function. 00:03:06.120 --> 00:03:10.800 So this is the original shopping basket. 00:03:10.920 --> 00:03:15.720 So we started our position 0. 00:03:16.410 --> 00:03:22.840 OK so we started there and we deleted a couple of items. 00:03:23.000 --> 00:03:27.540 So we chose two to delete so we deleted this one. 00:03:28.410 --> 00:03:29.310 OK. 00:03:29.340 --> 00:03:34.530 And this one. 00:03:37.450 --> 00:03:40.850 OK so first want bread and milk. 00:03:41.670 --> 00:03:46.710 So we deleted both of them and then we inserted this new array. 00:03:47.130 --> 00:03:49.170 OK. 00:03:49.940 --> 00:03:50.940 And we can see that. 00:03:50.940 --> 00:03:53.150 So Mongo cute. 00:03:54.830 --> 00:04:00.570 And then we continue with the other values of the original array. 00:04:01.590 --> 00:04:02.040 OK. 00:04:02.040 --> 00:04:02.760 So that's how it works. 00:04:02.760 --> 00:04:05.760 So the array splice function. 00:04:05.760 --> 00:04:10.100 So it will take an array as the first barometer. 00:04:10.110 --> 00:04:19.970 So if we specify the start position that is going to start from the deletes whatever we say literally 00:04:20.030 --> 00:04:20.100 . 00:04:20.160 --> 00:04:23.870 So if we said this to 0 for example. 00:04:23.930 --> 00:04:25.680 So we're not releasing anything. 00:04:26.070 --> 00:04:28.140 Then the results are going to be different. 00:04:28.140 --> 00:04:34.310 So if you're a page now we can see that we want to position zero. 00:04:34.700 --> 00:04:40.830 And just before position is 0 we are that Mangu and Kuei and we haven't deleted anything. 00:04:41.280 --> 00:04:51.690 OK but if we said that to 4 for example then that means that's opposite positions 0 we go into the leads 00:04:51.780 --> 00:04:57.550 for items and then just before we going to insert the new array. 00:04:57.660 --> 00:04:58.080 OK. 00:04:58.080 --> 00:05:04.440 So if the refresh the page this time we can see that we have deleted four items. 00:05:04.440 --> 00:05:07.060 Bread milk eggs and bread. 00:05:07.260 --> 00:05:08.060 OK. 00:05:08.070 --> 00:05:09.930 And then right before 00:05:13.110 --> 00:05:17.750 we have said that when you read that Mongo. 00:05:18.250 --> 00:05:25.340 OK so that's how the erase splice function works ok. 00:05:27.680 --> 00:05:28.240 Or it's 00:05:30.110 --> 00:05:32.190 . 00:05:35.280 --> 00:05:37.810 Now let's see how to sort. 00:05:37.820 --> 00:05:44.500 A certain array in ascending order so the function is pretty straight straightforward. 00:05:44.520 --> 00:05:50.870 It's Salt's followed by the name of the array to sort. 00:05:51.090 --> 00:06:00.990 OK Saud's shopping baskets and what's going to happen is that the value of the array is going to change 00:06:01.080 --> 00:06:04.460 and it's going to be sorted in ascending order. 00:06:04.640 --> 00:06:05.270 OK. 00:06:05.580 --> 00:06:08.040 So let's just echo this again 00:06:11.690 --> 00:06:16.400 and say sorted in ascending order. 00:06:17.160 --> 00:06:21.810 So if we refresh the page we can see that's our array. 00:06:21.810 --> 00:06:24.400 Now is sorted in ascending order. 00:06:24.660 --> 00:06:25.000 OK 00:06:31.790 --> 00:06:35.430 so is saucing with Upal then banana biscuits. 00:06:35.460 --> 00:06:39.320 I can see how the alphabetical order is followed. 00:06:39.620 --> 00:06:41.610 OK. 00:06:42.540 --> 00:06:51.840 All right if you want to sauces in descending order rather than using Saud's we can just use 00:06:58.260 --> 00:07:00.300 our sort for Reavis. 00:07:00.360 --> 00:07:00.830 OK. 00:07:01.110 --> 00:07:02.960 So now if we refresh. 00:07:03.280 --> 00:07:04.080 It's going to be 00:07:09.180 --> 00:07:12.240 it's going to be done the opposite way. 00:07:12.240 --> 00:07:16.030 So we finish with Apple and we start with yogurts. 00:07:16.080 --> 00:07:17.270 All right. 00:07:18.300 --> 00:07:23.740 OK so let's go back to the ascending order. 00:07:26.020 --> 00:07:28.620 OK. 00:07:29.400 --> 00:07:31.170 Now let's see how to source. 00:07:31.230 --> 00:07:32.400 As to race. 00:07:32.400 --> 00:07:32.900 OK. 00:07:33.000 --> 00:07:35.280 So let's creates an obsessive array. 00:07:35.310 --> 00:07:37.880 Call it comics. 00:07:38.840 --> 00:07:39.790 OK and we're going to 00:07:43.500 --> 00:07:54.040 place three elements the same size with. 00:08:00.060 --> 00:08:02.520 OK. 00:08:04.920 --> 00:08:07.530 So let's start with B-M. 00:08:07.690 --> 00:08:21.030 W is the key and with us to make and then the model X5 and then let's have the key. 00:08:21.200 --> 00:08:35.700 The second one is the make the model a 6 and the last one the key Mercedes for the make and the model 00:08:35.820 --> 00:08:39.230 is go for Cialis. 00:08:39.240 --> 00:08:41.310 OK. 00:08:43.800 --> 00:08:44.040 OK. 00:08:44.040 --> 00:08:50.630 So let's print this array before we sort it. 00:08:50.670 --> 00:08:52.410 So let's echo a paragraph first 00:08:54.930 --> 00:08:55.610 saying 00:08:59.710 --> 00:09:01.890 comics. 00:09:02.730 --> 00:09:11.820 And after that list brings the array using the print function and erase card makes. 00:09:11.990 --> 00:09:14.580 OK. 00:09:16.410 --> 00:09:16.930 OK. 00:09:17.040 --> 00:09:19.500 So that's our array. 00:09:20.250 --> 00:09:24.880 Ex wife. 00:09:27.760 --> 00:09:28.290 OK. 00:09:28.440 --> 00:09:29.560 So that's our array. 00:09:29.700 --> 00:09:40.740 Now we going to see how to sort the array either using the we you're going to start in ascending order 00:09:40.980 --> 00:09:46.260 by value or by key or by keys. 00:09:46.500 --> 00:09:51.020 OK so it starts with sorting by value. 00:09:51.310 --> 00:10:00.720 OK so we're going to use the function a sort. 00:10:01.160 --> 00:10:09.230 OK so this function is going to source the array in an ascending order by value. 00:10:09.270 --> 00:10:10.380 All right. 00:10:11.060 --> 00:10:14.560 Let's try this. 00:10:14.880 --> 00:10:18.210 Now if we preens the array again 00:10:20.990 --> 00:10:28.870 and this time he's going to be sorted in ascending order by Valy. 00:10:29.650 --> 00:10:32.940 OK so let's try this. 00:10:32.940 --> 00:10:38.900 So now if you look at the Values code A-6 CNS and then X5. 00:10:38.910 --> 00:10:42.520 So we have sorted the array in ascending order by value. 00:10:42.600 --> 00:10:44.040 OK. 00:10:46.260 --> 00:10:52.410 If we use the function a all. 00:10:52.440 --> 00:10:59.910 Rather than a source for reverse then it's going to be sorted in the opposite order by value. 00:11:00.080 --> 00:11:02.940 You can see every saucing this time by X5. 00:11:02.940 --> 00:11:04.580 That's less than a six. 00:11:04.650 --> 00:11:07.570 OK let's go back to the ascending order. 00:11:07.730 --> 00:11:08.690 OK. 00:11:09.030 --> 00:11:17.210 And now we are going to source the array by keys rather than values. 00:11:17.250 --> 00:11:23.310 So this time we are going to use another function that is called K sort's ok. 00:11:23.710 --> 00:11:30.060 K for keys and it is with the name of the array. 00:11:30.360 --> 00:11:37.500 Unless preens the array after this by this time we're going to say complex sorted in ascending order 00:11:37.610 --> 00:11:40.390 Viki's. 00:11:42.210 --> 00:11:46.500 OK so now if we refresh the page you can see that's 00:11:49.760 --> 00:11:50.350 the keys. 00:11:50.370 --> 00:11:53.570 Starts with Audi then BMW then Mercedes. 00:11:53.620 --> 00:11:54.210 OK. 00:11:54.470 --> 00:12:05.520 And similarly to sorting by values we can also sort of buy keys in the descending order if we add our 00:12:06.000 --> 00:12:06.690 after. 00:12:06.900 --> 00:12:09.440 OK. 00:12:09.480 --> 00:12:14.880 And you can see that now we sousing with Mercedes finishing with Audi. 00:12:15.680 --> 00:12:18.520 OK let's go back to the previous one. 00:12:18.930 --> 00:12:19.690 OK. 00:12:20.100 --> 00:12:30.990 So there was a quick overview of some important functions we can use in BHP to manipulate arrays we 00:12:30.990 --> 00:12:38.490 might cover other functions later on when we are building Web sites like converting arrays to strings 00:12:38.490 --> 00:12:41.640 or strings to arrays. 00:12:41.850 --> 00:12:47.220 OK so in the next video we'll learn how to send an email using BHB