Phpfor loop array-PHP source code

Source: Internet
Author: User
Expr1 is the initial value of the condition. Expr2 is a judgment condition, which is usually determined by using a logical operator number (logicaloperators. Expr3 is the part to be executed after statement is executed. It is used to change the condition for the next cycle to determine that expr1 is the initial value of the condition. Expr2 is the condition for judgment. It is usually determined by a logical operator number (logical operators. Expr3 is the part to be executed after statement is executed. It is used to change the condition for the next cycle to judge.

Script ec (2); script

/*
For syntax

The Code is as follows:
For (expr1; expr2; expr3 ){
Statement
}

See the for instance tutorial below

*/

The Code is as follows:
$ For = array (1, 2, 3, 4, 5, 6 );
$ ForFor = array (
Array (1 ),
Array (2 ),
Array (3)
);


// First, let's take a look at the instances that use the for loop for a group of data.

The Code is as follows:

$ ArrayLen = sizeof ($ );

For ($ I = 0; $ I <$ arrayLen; $ I ++)
{
Echo $ for [$ I],'
';
}


/*
Result
1
2
3
4
5
6
This is what we want.

For processing two-dimensional arrays

The Code is as follows:
*/
For ($ j = 0; $ j <$ arrayLen; $ j ++)
{
// Echo ($ forFor ($ j ));
}

// Fatal error: Function name must be a string in prompt

// We use foreach for another instance.

The Code is as follows:
Foreach ($ forFor as $ v => $ vv)
{
Print_r ($ vv );
}

/*
Output
(
[0] => 1
)
Array
(
[0] => 2
)
Array
(
[0] => 3
)
Exactly the data we want,

Summary
Each statement has its own purpose. We need to see how to use a function suitable for your current operation to quickly complete your work.
From the above, for is suitable for one-dimensional data and a single cycle. foreach can operate on one-dimensional data, such as two-dimensional data.

The original article on this site is reprinted to indicate from www.111cn.net/phper/php.html

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.