In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to use the List and each functions of PHP and their cooperation". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the List and each functions of PHP and their cooperation.
List function and each function are the functions that we often use in our daily life, so how should these two functions be used? What are the characteristics between the two? How do they work together? These two functions are more interesting array functions, the function is not difficult to learn, then let's take a look at it.
List function
List function its function is: can index array subscript 0 corresponding to variable 1, subscript 1 corresponding variable 2...list function can turn the array elements into variables to use.
Its basic syntax is:
List (variable 1, variable 2...)
Examples are as follows:
Output result:
From this, we can see that the subscript of "learn well" in the array is 0, which corresponds to $an in the list function; it can also be understood that the "learn well" value of 0 in the array is assigned to the $an in the list function, and so on. List is from left to right, one by one corresponding to the index array starting from 0 subscript value.
At the same time, there is another case, as follows:
Output result:
In the above example, the happiness with subscript 2 is left empty for the first two positions in the $c list, so there is no variable corresponding to study hard and make progress every day. So the list function strictly follows the one-to-one correspondence principle, that is, one variable of the list function corresponds to the element in the array with subscript 0, the subscript 1 corresponds to the second variable in the list function, and so on.
Of course, there is another case, as shown in the following example:
Output result:
In the above example, the subscript of the array has no subscript 0 and 1 in the array element because the key name starts directly from 2, so the variables an and b have no corresponding values. At the same time, only four variables are written in the list function, and there are no corresponding variables for happiness with subscript 4 and 5 in the array elements such as Donghai and longevity exceeding Nanshan.
Each function
The function of the each function is to pass an array. It splits one of the elements into a new array. Do this one element at a time. Move it one at a time, manipulating the next array element in the same way. At the end of the execution, false is returned.
Examples are as follows:
Output result:
You can see from the above example that the first time you run the each function, you learn to split the first element in the array element, aaa= >, into a new array. It can be understood that the each function reads the first element, unlocks the first element, puts the original value (study hard) in index subscript 1 in the new array, and puts the original key (aaa) in the associated subscript value, in the associated subscript key, and in the index subscript 0.
This is the result of running once, so let's take a look at how many times to run it. The example is as follows:
Output result:
As you can see, each read moves backwards, splitting each element into a new array, and when it is read to the end, there are no operable elements, and false is returned.
The cooperation of list and each
We know the functions of list and the functions of each, so what will be the different sparks when the two are used together?
Let's look at this through an example:
Output result:
In the above example, each takes the element apart, and then list assigns 0 = > aaa to the variable $key and 1 = > learns to assign to the variable $value. With the cooperation of the while loop statement we talked about earlier, we can get the following example:
Output result:
As you can see from the above results, each time a loop is executed, each is executed, then an element is moved backward, and the flash stop loop is returned at the end.
At this point, I believe you have a deeper understanding of "how to use PHP's List, each functions and coordination". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.