Difference between revisions of "PHP-and-MySQL/C2/Loops-Foreach-Statement/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(3 intermediate revisions by one other user not shown)
Line 4: Line 4:
 
|-
 
|-
 
|00:00
 
|00:00
|Welcome to the FOREACH loop tutorial.   
+
|Welcome to the '''foreach''' loop tutorial.   
 
|-
 
|-
 
|00:02
 
|00:02
|This is the last loop I'm going to cover.
+
|This is the last '''loop''' I'm going to cover.
 
|-
 
|-
 
|00:05
 
|00:05
|The basic fundamental of this loop is that it will loop through the values of an array
+
|The basic fundamental of this loop is that it will loop through the values of an '''array'''
 
|-
 
|-
 
|00:10
 
|00:10
|or the elements of an array
+
|or the '''elements''' of an array.
 
|-
 
|-
 
|00:13
 
|00:13
|I remember that in my earlier tutorials I said that the elements of an array are also called id tags
+
|I remember that in my earlier tutorials I said that the elements of an array are also called '''id tags'''.
 
|-
 
|-
 
|00:21
 
|00:21
|The elements of an array aren't called id tags
+
|The '''elements''' of an '''array''' aren't called '''id tags'''.
 
|-
 
|-
 
|00:24
 
|00:24
|When you're echoing out an array value
+
|When you're echoing out an array value,
 
|-
 
|-
 
|00:29
 
|00:29
|these here are the id - like numerical id, keys or tags  
+
|these here are the id - like numerical id, keys or tags.
 
|-
 
|-
 
|00:35
 
|00:35
|So I apologize for that   
+
|So, I apologize for that.  
 
|-
 
|-
 
|00:37
 
|00:37
|However lets get back to our FOREACH loop.  Now we'll create an array to start with
+
|However, let's get back to our '''foreach''' loop.  Now we'll create an array to start with.
 
|-
 
|-
 
|00:43
 
|00:43
|I'm going to call this numbers and its an array.  We now have to create these
+
|I'm going to call this '''numbers''' and it's an '''array'''.  We now have to create these.
 
|-
 
|-
 
|00:49
 
|00:49
|I've shown you this in my earlier tutorials and we'll have the numbers 1 2 3 4 5 6 7 8 9 and 10
+
|I've shown you this in my earlier tutorials and we'll have the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.
 
|-
 
|-
 
|01:00
 
|01:00
|Ok. So, a FOREACH is like this  
+
|OK. So, '''foreach''' is like this.
 
|-
 
|-
 
|01:03
 
|01:03
|So we have FOREACH and then we have our condition here .  Well I don't know what to call it
+
|So, we have '''foreach''' and then we have our '''condition''' here.  Well, I don't know what to call it.
 
|-
 
|-
 
|01:13
 
|01:13
|So, let me say the name of the array i.e. numbers
+
|So, let me say the name of the array i.e. '''numbers'''.
 
|-
 
|-
 
|01:21
 
|01:21
|And then we say as and then we say value.  So we can give this any name.   
+
|And then we say '''as''' and then we say '''$value'''.  So we can give this any name.   
 
|-
 
|-
 
|01:27
 
|01:27
|We could call it anything but I will type value
+
|We could call it anything but I will type '''$value'''.
 
|-
 
|-
 
|01:32
 
|01:32
|And then inside the curly brackets,  the fundamental command would be echo value
+
|And then inside the curly brackets,  the fundamental '''command''' would be '''echo''' '''$value'''.
 
|-
 
|-
 
|01:40
 
|01:40
|And we'll concatenate a line break in the end and lets have a look at this
+
|And we'll concatenate a line-break in the end and let's have a look at this.
 
|-
 
|-
 
|01:46
 
|01:46
| So that echoed through our loop. Its a really easy way to echo through our loop. You can use other loops to echo through an array. You have to write it manually, however and this is probably the easiest way to do it.
+
|So, that echoed through our loop. It's a really easy way to '''echo''' through our loop. You can use other loops to echo through an '''array'''. You have to write it manually, however and this is probably the easiest way to do it.
 
|-
 
|-
 
|02:00
 
|02:00
|So as long as you remember this, you can echo through your array, perform operations on each part of your array and then maybe store it in a new array
+
|So, may be... as long as you remember this, you can '''echo''' through your array, perform '''operations''' on each part of your array and then may be store it in a new array.
 
|-
 
|-
 
|02:08
 
|02:08
|However I'm going to show you how to manipulate in a simple way
+
|However, I'm going to show you how to manipulate in a simple way.
 
|-
 
|-
 
|02:12
 
|02:12
|Now what I'll do is - I'm going to do the 2 times table.
+
|Now, what I'll do is - I'm going to do the '2 times' table.
 
|-
 
|-
 
|02:19
 
|02:19
|So I'll scrap this and I'll say the following.
+
|So, I'll scrap this and I'll say the following.
 
|-
 
|-
 
|02:23
 
|02:23
|So I need the number in the array here times 2 is and then outside of this is going to be the new value.  So we're going to times each element of the array - each number in the array by 2
+
|So, I need the number in the array here '''times 2 is''' and then outside of this is going to be the new value.  So we're going to times each element of the array - each number in the array by 2.
 
|-
 
|-
 
|02:41
 
|02:41
|Let's start out by saying numbers
+
|Let's start out by saying '''numbers'''.
 
|-
 
|-
 
|02:46
 
|02:46
|Sorry, we're going to say value because we have stored each FOREACH element in this variable name value
+
|Sorry, we're going to say '''$value''' because we have stored each '''foreach''' element in this variable name '''$value'''.
 
|-
 
|-
 
|02:56
 
|02:56
|So value is each of these in turn through the loop
+
|So, '''$value''' is each of these in turn, through the loop.
 
|-
 
|-
 
|03:00
 
|03:00
|Therefore, value times 2 is, and then after this we'll put some brackets.  Inside we'll type value times 2
+
|Therefore, '''$value times 2 is''' and then after this we'll put some brackets.  Inside we'll type: $value * (times) 2.
 
|-
 
|-
 
|03:10
 
|03:10
|Remember this is a mathematical operator - an arithmetical operator that I showed you earlier
+
|Remember, this is a mathematical operator - an arithmetical operator that I showed you earlier.
 
|-
 
|-
 
|03:15
 
|03:15
|It is a mathematical operator but the correct name is arithmetic  
+
|It is a mathematical operator but the correct name is arithmetic.
 
|-
 
|-
 
|03:20
 
|03:20
|OK. This is going to multiply by two  
+
|OK. This is going to multiply by two.
 
|-
 
|-
 
|03:24
 
|03:24
|Now to make this interesting what I'll do is to make this as a multiple
+
|Now, to make this interesting, what I'll do is to make this as a '''$multiple''',
 
|-
 
|-
 
|03:30
 
|03:30
Line 106: Line 106:
 
|-
 
|-
 
|03:32
 
|03:32
|and the multiple up here
+
|and the '''$multiple''' up here
 
|-
 
|-
 
|03:35
 
|03:35
|is going to equal 2.  So you can guess by now that I've basically replaced that
+
|is going to equal to 2.  So you can guess by now that I've basically replaced that.
 
|-
 
|-
 
|03:41
 
|03:41
|I can change this as I please
+
|I can change this as I please.
 
|-
 
|-
 
|03:43
 
|03:43
|Lets load this and refresh
+
|Let's load this and '''refresh'''.
 
|-
 
|-
 
|03:46
 
|03:46
|Oh! We forgot the break
+
|Oh! We forgot the '''break'''.
 
|-
 
|-
 
|03:48
 
|03:48
|So, lets just add that in the end here
+
|So, let's just add that in the end here.
 
|-
 
|-
 
|03:51
 
|03:51
|Well as we can't read it
+
|Well, as we can't read it.
 
|-
 
|-
 
|03:54
 
|03:54
|Sorry, 1 times 2 is 2
+
|Sorry, 1 times 2 is 2.
 
|-
 
|-
 
|03:58
 
|03:58
|2 times 2 is 4 all the way up to 10 times 2 is 20
+
|2 times 2 is 4, all the way up to 10 times 2 is 20.
 
|-
 
|-
 
|04:03
 
|04:03
|We know that these are all correct
+
|We know that these are all correct.
 
|-
 
|-
 
|04:05
 
|04:05
|We can change this, lets say we want the 10 times table
+
|We can change this, let's say we want the '10 times' table.
 
|-
 
|-
 
|04:10
 
|04:10
|refresh, 1 times 2 is... Oh! nah, we forgot to change this 2 into multiple
+
|'''Refresh''', 1 times 2 is... Oh! nah, we forgot to change this 2 into '''$multiple'''.
 
|-
 
|-
 
|04:20
 
|04:20
|Now it will echo our number  
+
|Now it will '''echo''' our number.
 
|-
 
|-
 
|04:23
 
|04:23
|Refresh
+
|'''Refresh'''. So, 1 times 10 is 10, 2 times 10 is 20, 10 times 10 is a hundred.
|-
+
|04:24
+
|So 1 times 10 is 10, 2 times 2 is, 2 times 10 is 20, 10 times 10 is a hundred
+
 
|-
 
|-
 
|04:30
 
|04:30
|So as long as we change the value of the multiple - lets say the 12 times table  
+
|So, as long as we change the value of the '''$multiple''' - let's say the '12 times' table.
 
|-
 
|-
 
|04:36
 
|04:36
|Our 2 values are going to change
+
|Our 2 values are going to change.
 
|-
 
|-
 
|04:39
 
|04:39
Line 160: Line 157:
 
|-
 
|-
 
|04:41
 
|04:41
|So from this FOREACH loop and array I've created a really basic, multiple program with which you can see the times table for any set of numbers you like
+
|So, from this '''foreach''' loop and array I've created a really basic, multiple program with which you can see the 'times table' for any set of numbers you like.
 
|-
 
|-
 
|04:51
 
|04:51
|So that's the FOREACH loop.  Thanks for watching.
+
|So that's the '''foreach''' loop.  Thanks for watching.
 
|-
 
|-
 
|04:54
 
|04:54
|This is Madhur dubbing for the Spoken Tutorial Project.
+
|This is Madhur, dubbing for the Spoken Tutorial Project.
 
|-
 
|-

Latest revision as of 15:26, 24 March 2017

Time Narration
00:00 Welcome to the foreach loop tutorial.
00:02 This is the last loop I'm going to cover.
00:05 The basic fundamental of this loop is that it will loop through the values of an array
00:10 or the elements of an array.
00:13 I remember that in my earlier tutorials I said that the elements of an array are also called id tags.
00:21 The elements of an array aren't called id tags.
00:24 When you're echoing out an array value,
00:29 these here are the id - like numerical id, keys or tags.
00:35 So, I apologize for that.
00:37 However, let's get back to our foreach loop. Now we'll create an array to start with.
00:43 I'm going to call this numbers and it's an array. We now have to create these.
00:49 I've shown you this in my earlier tutorials and we'll have the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.
01:00 OK. So, foreach is like this.
01:03 So, we have foreach and then we have our condition here. Well, I don't know what to call it.
01:13 So, let me say the name of the array i.e. numbers.
01:21 And then we say as and then we say $value. So we can give this any name.
01:27 We could call it anything but I will type $value.
01:32 And then inside the curly brackets, the fundamental command would be echo $value.
01:40 And we'll concatenate a line-break in the end and let's have a look at this.
01:46 So, that echoed through our loop. It's a really easy way to echo through our loop. You can use other loops to echo through an array. You have to write it manually, however and this is probably the easiest way to do it.
02:00 So, may be... as long as you remember this, you can echo through your array, perform operations on each part of your array and then may be store it in a new array.
02:08 However, I'm going to show you how to manipulate in a simple way.
02:12 Now, what I'll do is - I'm going to do the '2 times' table.
02:19 So, I'll scrap this and I'll say the following.
02:23 So, I need the number in the array here times 2 is and then outside of this is going to be the new value. So we're going to times each element of the array - each number in the array by 2.
02:41 Let's start out by saying numbers.
02:46 Sorry, we're going to say $value because we have stored each foreach element in this variable name $value.
02:56 So, $value is each of these in turn, through the loop.
03:00 Therefore, $value times 2 is and then after this we'll put some brackets. Inside we'll type: $value * (times) 2.
03:10 Remember, this is a mathematical operator - an arithmetical operator that I showed you earlier.
03:15 It is a mathematical operator but the correct name is arithmetic.
03:20 OK. This is going to multiply by two.
03:24 Now, to make this interesting, what I'll do is to make this as a $multiple,
03:30 as a new variable
03:32 and the $multiple up here
03:35 is going to equal to 2. So you can guess by now that I've basically replaced that.
03:41 I can change this as I please.
03:43 Let's load this and refresh.
03:46 Oh! We forgot the break.
03:48 So, let's just add that in the end here.
03:51 Well, as we can't read it.
03:54 Sorry, 1 times 2 is 2.
03:58 2 times 2 is 4, all the way up to 10 times 2 is 20.
04:03 We know that these are all correct.
04:05 We can change this, let's say we want the '10 times' table.
04:10 Refresh, 1 times 2 is... Oh! nah, we forgot to change this 2 into $multiple.
04:20 Now it will echo our number.
04:23 Refresh. So, 1 times 10 is 10, 2 times 10 is 20, 10 times 10 is a hundred.
04:30 So, as long as we change the value of the $multiple - let's say the '12 times' table.
04:36 Our 2 values are going to change.
04:39 There we are.
04:41 So, from this foreach loop and array I've created a really basic, multiple program with which you can see the 'times table' for any set of numbers you like.
04:51 So that's the foreach loop. Thanks for watching.
04:54 This is Madhur, dubbing for the Spoken Tutorial Project.

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Pratik kamble, Sandhya.np14