PHP - TRICKS WITH FOR LOOPS

Поділитися
Вставка
  • Опубліковано 19 вер 2024

КОМЕНТАРІ • 51

  • @mystique9
    @mystique9 4 роки тому +2

    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!

  • @Chandrajith100
    @Chandrajith100 4 роки тому +1

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

  • @theepicdot
    @theepicdot 5 років тому +1

    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

  • @JP-lr8rr
    @JP-lr8rr 6 років тому +18

    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.

    • @walnut2983
      @walnut2983 6 років тому +4

      oj just add 1 to $x

    • @StefanNovovic
      @StefanNovovic 4 роки тому +2

      Use foreach($array as $k=>$v), you get keys indexed from 0 to whatever and your values ofc.

  • @vNYCblade
    @vNYCblade 6 років тому +4

    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...

  • @mauricemakesmovies
    @mauricemakesmovies 4 роки тому

    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!

    • @phpBasics
      @phpBasics  4 роки тому +1

      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.

    • @mauricemakesmovies
      @mauricemakesmovies 4 роки тому

      @@phpBasics Thanks for your fast reply. I subscribed anyway just in case 🤗

  • @samkthampan
    @samkthampan 4 роки тому +1

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

  • @topmoviescene9019
    @topmoviescene9019 4 роки тому +1

    thank you

  • @mdarifulislam1044
    @mdarifulislam1044 4 роки тому

    Amazing video

  • @subhashchaudhary
    @subhashchaudhary 7 років тому

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

  • @DineshKumar-fl6db
    @DineshKumar-fl6db 5 років тому +1

    Amazing explanation sir thank you so much share this vedio

  • @narsimhanarsimha7932
    @narsimhanarsimha7932 3 роки тому

    Excellent

  • @UnnamedUnnamed-em3gj
    @UnnamedUnnamed-em3gj 4 роки тому +1

    You deserve sub bro.

  • @shetuamin
    @shetuamin 4 роки тому

    Thanks.

  • @rimantasdanilevicius6754
    @rimantasdanilevicius6754 5 років тому

    Good and time saving php tricks, thanks!

  • @sadhikhussain1986
    @sadhikhussain1986 4 роки тому

    Simple and easy. Thank you

  • @awaisxwati3459
    @awaisxwati3459 5 років тому +1

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

  • @mphomanaka2263
    @mphomanaka2263 3 роки тому

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

  • @bestoffer5054
    @bestoffer5054 5 років тому

    this is magic great job

  • @mayankpandey6051
    @mayankpandey6051 4 роки тому

    good explaining thanks.

  • @shagiwal100
    @shagiwal100 7 років тому +1

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

  • @syediqbalahmed3176
    @syediqbalahmed3176 4 роки тому

    nice ...

  • @sujeewakrishanthagamage2459
    @sujeewakrishanthagamage2459 6 років тому

    Thank you soooooooooooooooooooooooooooooooooooooo much!

  • @nesyourys3766
    @nesyourys3766 3 роки тому

    It's very effective

  • @yagami5160
    @yagami5160 6 років тому

    Thanks a lot, best wishes and good explaining

  • @FGj-xj7rd
    @FGj-xj7rd 3 роки тому

    This is some serious gourmet shit.

  • @nazirulaliff5513
    @nazirulaliff5513 6 років тому

    Sir, you're my hero! Subscribed!

  • @faiezahmedkhan
    @faiezahmedkhan 5 років тому

    great video you should make more video

  • @najeebalishah9896
    @najeebalishah9896 5 років тому

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

  • @Little_Grey_Cells
    @Little_Grey_Cells 5 років тому

    I like this tricks. .expected more

  • @abdiag603
    @abdiag603 2 роки тому

    What if the value of y and x are not same e.g x

  • @inquisitive35
    @inquisitive35 8 років тому

    wonderful!

  • @Drumronron
    @Drumronron 6 років тому

    Thank you! :-)

  • @janezklun
    @janezklun 7 років тому

    Good one

  • @mardyart
    @mardyart 3 роки тому

    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.

  • @sujitkumarsoren7646
    @sujitkumarsoren7646 7 років тому

    Nice👍

  • @MrGilly
    @MrGilly 6 років тому

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

  • @gomo8651
    @gomo8651 6 років тому

    Eurekah!...thanks mate :)

  • @pianoLee-sx9dx
    @pianoLee-sx9dx 6 років тому

    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

  • @KhaledQweder
    @KhaledQweder 7 років тому +1

    1000 Like.

  • @temitopeolaoluwa
    @temitopeolaoluwa 2 роки тому

    Where are the comments. The code ain't working

    • @phpBasics
      @phpBasics  2 роки тому

      which part

    • @temitopeolaoluwa
      @temitopeolaoluwa 2 роки тому

      @@phpBasics the array with forloop. I created an array with number ranges '1-5', '6-10' and so on but it her responds

  • @MyCity4You
    @MyCity4You 7 років тому +2

    x+1

  • @WaRKinG15
    @WaRKinG15 5 років тому

    really basic php stuff