PHP Arrays ELEGANT AND EASY WAYS TO WORK WITH THEM. PART1
I wonder what arrays are all about! Well, to begin with they are used to store data. Just like you store data in variables E.g. $x=5; The major difference between arrays and variables being: Variables aren’t as flexible as arrays. Arrays can be used to store Homogeneous(All Ints or Floats) or Heterogeneous(Int, Float, Char) data.
Tell me more There are 3 types of arrays in PHP Indexed: Accessed via a particular Index. E.g. $x[0]; Associative: Accessed via a particular key. E.g. $x[‘name’]; Multidimensional: Contain more than one arrays of same or different types. E.g. $x[0][1];
Indexed arrays How do I declare and initialize them? $country = array(“India”, “Canada”, “USA”); That’s how you do it. Don’t use the other way. It’s time consuming!
Indexed arrays I want some action! Show me how to view contents of the array we just created. Okay, here you go – This is how you access the elements. Echo $country[1]; #Will show you Canada. Why? Arrays start with a ‘0’ as primary Index.
Indexed arrays - Show me more! That was kids stuff. Show me how to print all the elements. Hmm, you want more action huh? Here you go – For($anyvariable=0; $anyvariable<count($country); $anyvariable++){ Echo $country[$anyvariable]; } Note: count function will contain the length of the array. In this case 3.
Indexed arrays - Pay back time! Are you kidding me? “Practice makes a man perfect” You show me more; assignment time! a. Create an array with numbers 1 to 20 inside it. b. Show me how you’d print every odd number between 3 and 20. c. If that was fun, when you arrive at the 17 make it yell out “Seventeen”. Did you make it till here already? Very good. I appreciate your time and efforts.
End of Part1  End of Part1.  This document will contain links to all other documents when complete.  Estimated completion time: December 5th 2015 or sooner.

Php arrays

  • 1.
    PHP Arrays ELEGANT ANDEASY WAYS TO WORK WITH THEM. PART1
  • 2.
    I wonder whatarrays are all about! Well, to begin with they are used to store data. Just like you store data in variables E.g. $x=5; The major difference between arrays and variables being: Variables aren’t as flexible as arrays. Arrays can be used to store Homogeneous(All Ints or Floats) or Heterogeneous(Int, Float, Char) data.
  • 3.
    Tell me more Thereare 3 types of arrays in PHP Indexed: Accessed via a particular Index. E.g. $x[0]; Associative: Accessed via a particular key. E.g. $x[‘name’]; Multidimensional: Contain more than one arrays of same or different types. E.g. $x[0][1];
  • 4.
    Indexed arrays How doI declare and initialize them? $country = array(“India”, “Canada”, “USA”); That’s how you do it. Don’t use the other way. It’s time consuming!
  • 5.
    Indexed arrays I wantsome action! Show me how to view contents of the array we just created. Okay, here you go – This is how you access the elements. Echo $country[1]; #Will show you Canada. Why? Arrays start with a ‘0’ as primary Index.
  • 6.
    Indexed arrays -Show me more! That was kids stuff. Show me how to print all the elements. Hmm, you want more action huh? Here you go – For($anyvariable=0; $anyvariable<count($country); $anyvariable++){ Echo $country[$anyvariable]; } Note: count function will contain the length of the array. In this case 3.
  • 7.
    Indexed arrays -Pay back time! Are you kidding me? “Practice makes a man perfect” You show me more; assignment time! a. Create an array with numbers 1 to 20 inside it. b. Show me how you’d print every odd number between 3 and 20. c. If that was fun, when you arrive at the 17 make it yell out “Seventeen”. Did you make it till here already? Very good. I appreciate your time and efforts.
  • 8.
    End of Part1 End of Part1.  This document will contain links to all other documents when complete.  Estimated completion time: December 5th 2015 or sooner.