Background: In the thinkphp framework, I use the foreach loop to generate a cache, and then call the cache under other control and methods. The problem is that on-demand generation is ruled out first, because we are not sure that one of the more than 60 thousand pieces of data can be used, so we need to generate all the content, because it takes too much time to generate the content... background: In the th
The amp; pass-through reference problem in PHP. what is the principle of the output result after the result of the foreach loop ?, PHP. In PHP, the result of the foreach loop can help explain the principle of the output result ?, In PHPPHP, the result of the foreach
Recently I bought php and mysqlweb development and saw the array loop statement. It is worth your attention. I would like to keep some handwriting so that I can read more foreach later.
The code is as follows:
$ Price = array ('apple' => 10, 'Orange '=> 20, 'banner' => 30 );Foreach ($ price as $ key => $ value){Echo $ key. '=>'. $ value .'';}Echo'';?>
There
foreach Loop comparison of several programming languages
The Foreach Loop, as the "enhanced version" of the "for" loop, has been widely used in several programming languages (Java, C #, PHP) because it can traverse array elements in a simpler way. In different languages, h
This paper mainly introduces the difference between for loop and foreach in PHP, which has good reference value. Let's take a look at the little series.
The difference between A for loop and foreach
foreach relies on IEnumerable.
The first time var A in GetList () is cal
If you use foreach to loop the two-dimensional array, the second loop will not be displayed, but if you comment out the first loop, the content of the second loop will be displayed normally, which of your friends knows the reason? thank you very much! PHPcode $ products2 = a
I found a problem that is easy to make mistakes, but does not understand the principle, but does not understand the problem. if you encounter a similar problem, you can refer to it.
The code is as follows:
Foreach ($ array as $ row ){$ Row = explode ('/', $ row );}Foreach ($ array as $ row ){// Do something}
In this case, a logic error occurs in the second loop
code block when the specified condition is true.
For loop
The For loop is used when you know beforehand how many times a script needs to run.
Grammar
for (initial value; condition increment;) {The code to execute}
Initial value: Primarily initializes a variable value that is used to set a counter (but can be any code that executes once at the beginning of the loop
code as follows:
$price =array (' Apple ' =>10, ' orange ' =>20, ' banner ' =>30);foreach ($price as $key = $value){echo $key. ' = '. $value. '';}Echo '';Reset ($price);while (list ($key, $value) =each ($price)){echo "$key = $value", "";}?>
This allows you to still use the array $price.
Some books, as a novice I, I do, knock down to see the effect, understand, write a post, easy to forget to look at later, said the relatively superficial, poor la
Php jumps out of the foreachfor loop implementation program. There are several methods to jump out of the loop in php, one is to use goto, and the other is to use the new php goto command. I will introduce it below. Break is used in various loops mentioned above. There are several methods to jump out of the loop in php. one is to use goto, and the other is to use
There are several methods to jump out of the loop in php, one is to use goto, and the other is to use the new php goto command. I will introduce it below.
Break is used in various loops and switch statements mentioned above. Its role is to jump out of the current syntax structure and execute the following statements. The break statement can contain a parameter n, indicating the number of layers that exit the loop
corresponding $b unless it is specified again as another reference, or unset ($a).
For you this foreach, is the same truth, you take the loop apart, this is the way:
$value = $a[0];$value = 5;$value = $a[1];$value = 5;$value = $a[2];$value = 5;
The loop runs to the last time, $value is a reference to $a[2], so it is equivalent to this form:
$a[0] = 5;$a[1] = 5;$
Let's take a look at the following three cycles:
Int [] foo = new int [100];
1, foreach (int I in foo)Console. WriteLine (I. ToString ());
2, for (int index = 0; index Console. WriteLine (foo [index]. ToString ());
3, int len = foo. Length;For (int index = 0; index Console. WriteLine (foo [index]. ToString ());These three loops are what I have read in valid CIDR blocks. I found that the third loop is equiva
Smarty uses the section or foreach loop, and the page is not displayed. I found that as long as an array loop, section, or foreach is used on the html page, the page is blank, and the array passed through is also valuable, if the variable is passed in, no problem occurs. For example, $ smarty- gt; assign ("title", nbs
Found an error-prone, but do not understand the principle of the explanation does not understand the problem, encounter similar problems of friends can refer to.Copy the Code code as follows:foreach ($array as $v) {$v = explode ('/', $v);}foreach ($array as $v) {Do something}In this case, in the second loop there will be a logic error, adding the second loop whe
Recommendation 17: Loop traversal with foreach in most casesSince this recommendation involves the traversal of a collection, let's consider how to traverse the binding before starting this recommendation. Suppose there is an array whose traversal pattern can be traversed by the index, and if there is a Hashtable, the traversal pattern may be traversed by the key value. Regardless of which collection, if th
$a = Array (' A ', ' B ', ' C '), foreach ($a as $v) {}foreach ($a as $v) {}var_dump ($a);Right now. Don't open your browser and guess. What is the result of the output?Children's shoes, which are more familiar with references, may already be seen. The correct answer is: Array (3) {[0]=> string (1) "A" [1]=> string (1) "B" [2]=> string (1) "B"} is a,b,b. If you're guessing that's a,b,c. So for reference, y
Break is used in various loops and switch statements mentioned above. Its role is to jump out of the current syntax structure and execute the following statements. The break statement can contain a parameter n, indicating the number of layers that exit the loop. To jump out of multiple loops, you can use n to represent the number of layers that exit the loop.// The Current php
The difference between A for loop and foreach
foreach relies on IEnumerable.
The first time var A in GetList () is called GetEnumerator returns the first object and assigns A,
The MoveNext is called after each subsequent execution of Var A in GetList (). Until the end of the loop.
The period getlist () method exec
Ecshop template variable loop foreach, ecshopforeach
Ecshop is a new version of smarty. It deletes some functions. For example, the four arithmetic operations in the template are deleted. For example, if we want to obtain the cyclic key + 1 through the arithmetic operation, we cannot get its value, however, we can use other methods.
. Iteration
Iteration contains the current
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.