PHP - TRICKS WITH FOR LOOPS

preview_player
Показать описание
Learn some useful and useLESS ways to utilize FOR loops!
Рекомендации по теме
Комментарии
Автор

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!

mystique
Автор

This is very pleasant and specific to the point video I saw. Thank you very much!!!

Chandrajith
Автор

I think adding x+1 at name attribute is much better than adding a empty space for the prgm related to

samkthampan
Автор

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.

JP-lrrr
Автор

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

theepicdot
Автор

I'm uncertain whether you're still active on YouTube, 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!

mauricemakesmovies
Автор

Powerful, very insight and jejune... just subscribed and think am gonna learn more from you ❤️🔥👊

mphomanaka
Автор

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} <br>"; // 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...

vNYCblade
Автор

i really like this video very much, ,, keep posting video like this, ,,i really ove to watch and we will keep sharing this ...

subhashchaudhary
Автор

Amazing explanation sir thank you so much share this vedio

DineshKumar-fldb
Автор

thanks sir its very easy and simple trick so please make more php foreach loop tutorial thanks

awaisxwati
Автор

What if the value of y and x are not same e.g x<=8 and y<=10

abdiag
Автор

it's very helpful tutorial, especially the last table which you created...

shagiwal
Автор

Good and time saving php tricks, thanks!

rimantasdanilevicius
Автор

great video you should make more video

faiezahmedkhan
Автор

Sir, you're my hero! Subscribed!

nazirulaliff
Автор

Thanks a lot, best wishes and good explaining

yagami
Автор

sir an awosome lecture to play with for loop...
Kindly make a lecture on how to play with mysqli queries...that would be great!!!

najeebalishah
Автор

Instead of doing a FOR loop for the months array you can just use a for each loop.

MrGilly
Автор

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<= $resultCheck; $i++) {

echo '<div class="star1">
<i class="fas fa-star fa-10x"></i></div>';

if ($i == 5 ) {
$i =0;

pianoLee-sxdx