Course Title: Web Development Masterclass
Course Link: http://youaccel.com/admin/cdisplay.ph...
Facebook: / youaccel
Twitter: / youaccel
Website: http://youaccel.com
Tutorial Content:
In this lecture we will explore PHP Arrays. We have already had a bit of exposure to arrays in some of the previous lessons.
An array is a variable that can store multiple values.
In PHP there are three types of arrays:
Indexed arrays
Associative arrays
Multidimensional arrays
We will start with an example of an indexed array.
Here, we have a variable named colors. The variable contains three values, blue, green, and red.
We can output each value in the array by specifying its unique index number in square brackets, next to the array variable name. An index always starts with the number 0. The 0 is assigned to the first value in the array. So in this case, blue would have the index number 0. The index increments by 1, so the value green would have index number 1, and red would have index number 2.
We can use the count() function to return the length, or number of values in an array. In this case we have three values.
By typing count(Colors) we can see the number 3 outputted in our web browser.
We can loop through the values of an indexed array using the for loop.
First we specify we want the value of x to start at 0 and increment by 1, upto the length of the array.
The length is obtained using our count function and storing the value in variable arrlength.
Next we simply loop through each index number in our array, which will output the value attached to the index number.
The next type of array we want to explore is the Associative Array.
This type of an array allows us to assign values to our elements, referred to as named keys.
In this example, we have created an associate array variable named tscore. For the purpose of this example, we will assume tscore holds the mark that students scored on a test out of 100.
tscore, has three elements, John, Bill and Dan. Each element has a name key, or value assigned to it.
John is assigned the value 60, Bill - 80 and Dan - 75.
Next we use our echo statement to output the the mark that Bill got on the test.
We do that using our echo statement, and inserting the named key in square brackets next to the associative array name.
We can loop through an associative array using the foreach loop. In our browser we can see the output.
Auf dieser Seite können Sie das Online-Video PHP Arrays | Tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer YouAccel 09 Mai 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 6 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!