Instead of putting an empty element into the array, just start like this: $months = [ 1 => "January", "February", "March" ... ] It starts the element key at One instead of Zero and increments it by 1 for every upcoming element.
I know this video was related to ForLoops specifically, BUT, since once of the examples was how to generate sequential lists, specifically one with months of the year, i though it would be helpful to show a different way of doing it which is more advanced, BUT simpler and a lot more dynamic... $months = range(1,12); // This simple function generates an indexed array with values starting with 1 and ending with 12... This is the output of $months... Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12 ) foreach($months as $month) { $monthName = date("F", mktime(0,0,0,$month,10)); // This function DATE() creates and Formats a date... since we dont care about an actual date but only a partial of a date, specifically the name of the month based on its numeric representation, we can generate a partial DATE containing the NAME of the month only... thats what "F" flag represents... echo "Month #{$month} is known as {$monthName} "; // Here is simply substitutes values for variables as the loop is processed... } This is the output of the loop: --- Month #1 is known as January Month #2 is known as February Month #3 is known as March Month #4 is known as April Month #5 is known as May Month #6 is known as June Month #7 is known as July Month #8 is known as August Month #9 is known as September Month #10 is known as October Month #11 is known as November Month #12 is known as December --- This is a much more efficient way to generate lists... you can wrap this code in a function and reuse it wherever you have forms with month selects or whatever... You can easily extend this to be multi lingual, etc...
I'm uncertain whether you're still active on UA-cam, but you have a great way of explaining and your voice is also relaxing to listen to. I hope you keep uploading, very helpful and clear tutorials!
Greetings! I am still very active helping visitors with their projects. I simply have not had an opportunity to upload anything lately, but have a lot of great content coming soon.
I have the following code and I am trying to give the user a sticker everytime they enter something into the database.. This does work but how would I reset the counter? if they have already received 5 stickers and I want the sticker to start again at the beginning of a page, I tried to do something like this but it keeps looping... for ($i = 1; $i
It was a good video and I watched it all the way through. But I was disappointed. It said 'tricks' but these are just standard practice for loops. I though you were gonna show some wizardry I'd never seen before. Still gets a thumbs up from me even if it is 5 years old.
You're a wonderful teacher. I really liked the way you go step by step. I'm looking forward to seeing more of your educational videos. Thank you!
I think adding x+1 at name attribute is much better than adding a empty space for the prgm related to month......
This is very pleasant and specific to the point video I saw. Thank you very much!!!
Instead of putting an empty element into the array, just start like this:
$months = [ 1 => "January", "February", "March" ... ]
It starts the element key at One instead of Zero and increments it by 1 for every upcoming element.
oj just add 1 to $x
Use foreach($array as $k=>$v), you get keys indexed from 0 to whatever and your values ofc.
I know this video was related to ForLoops specifically, BUT, since once of the examples was how to generate sequential lists, specifically one with months of the year, i though it would be helpful to show a different way of doing it which is more advanced, BUT simpler and a lot more dynamic...
$months = range(1,12); // This simple function generates an indexed array with values starting with 1 and ending with 12...
This is the output of $months...
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
[10] => 11
[11] => 12
)
foreach($months as $month)
{
$monthName = date("F", mktime(0,0,0,$month,10)); // This function DATE() creates and Formats a date... since we dont care about an actual date but only a partial of a date, specifically the name of the month based on its numeric representation, we can generate a partial DATE containing the NAME of the month only... thats what "F" flag represents...
echo "Month #{$month} is known as {$monthName} "; // Here is simply substitutes values for variables as the loop is processed...
}
This is the output of the loop:
---
Month #1 is known as January
Month #2 is known as February
Month #3 is known as March
Month #4 is known as April
Month #5 is known as May
Month #6 is known as June
Month #7 is known as July
Month #8 is known as August
Month #9 is known as September
Month #10 is known as October
Month #11 is known as November
Month #12 is known as December
---
This is a much more efficient way to generate lists... you can wrap this code in a function and reuse it wherever you have forms with month selects or whatever... You can easily extend this to be multi lingual, etc...
Thanks
Love your videos and your explanations, am a complete php novice but with your videos, am sure to get it right in my journey as a PDP beginner
I'm uncertain whether you're still active on UA-cam, but you have a great way of explaining and your voice is also relaxing to listen to. I hope you keep uploading, very helpful and clear tutorials!
Greetings! I am still very active helping visitors with their projects. I simply have not had an opportunity to upload anything lately, but have a lot of great content coming soon.
@@phpBasics Thanks for your fast reply. I subscribed anyway just in case 🤗
Amazing explanation sir thank you so much share this vedio
thank you
Amazing video
i really like this video very much ,,, keep posting video like this ,,,i really ove to watch and we will keep sharing this ...
Simple and easy. Thank you
Powerful, very insight and jejune... just subscribed and think am gonna learn more from you ❤️🔥👊
You deserve sub bro.
Excellent
What if the value of y and x are not same e.g x
good explaining thanks.
thanks sir its very easy and simple trick so please make more php foreach loop tutorial thanks
Thanks.
This is some serious gourmet shit.
great video you should make more video
this is magic great job
Good and time saving php tricks, thanks!
it's very helpful tutorial, especially the last table which you created...
Thanks a lot, best wishes and good explaining
Instead of doing a FOR loop for the months array you can just use a for each loop.
Sir, you're my hero! Subscribed!
I have the following code and I am trying to give the user a sticker everytime they enter something into the database.. This does work but how would I reset the counter? if they have already received 5 stickers and I want the sticker to start again at the beginning of a page, I tried to do something like this but it keeps looping...
for ($i = 1; $i
nice ...
Thank you soooooooooooooooooooooooooooooooooooooo much!
It's very effective
I like this tricks. .expected more
sir an awosome lecture to play with for loop...
Kindly make a lecture on how to play with mysqli queries...that would be great!!!
wonderful!
Where are the comments. The code ain't working
which part
@@phpBasics the array with forloop. I created an array with number ranges '1-5', '6-10' and so on but it her responds
Eurekah!...thanks mate :)
Thank you! :-)
Nice👍
Good one
It was a good video and I watched it all the way through. But I was disappointed. It said 'tricks' but these are just standard practice for loops. I though you were gonna show some wizardry I'd never seen before. Still gets a thumbs up from me even if it is 5 years old.
1000 Like.
x+1
really basic php stuff