Php traversal array methods-PHP source code

Source: Internet
Author: User
Ec (2); in the php tutorial, we commonly use two methods to traverse data. We use for and foreach for operations. The former is to know the Data Length, the latter may not know the data length. The following is an example. & Lt ;? $ Arrayarray (1, 2, 3, 4, 5, www.111cn.net, www.111cn.net); for ($ i0; $ I & lt; count ($ array); $ I ++) {& nbsp; e script ec (2); script

In the php tutorial, we commonly use two methods to traverse data, namely for and foreach. The former is to know the data length, and the latter can not know the Data Length, the following is an example.

$ Array = array (1, 2, 3, 4, 5, 'www .111cn.net ', 'www .111cn.net ');
For ($ I = 0; $ I
{
Echo $ array [$ I].'
';
}

The output result is as follows:
1
2
3
4
5
Www.111cn.net
Www.111cn.net

Foreach ($ array as $ v => $ vv)
{
Echo $ vv .'
';
}

The output result is as follows:

1
2
3
4
5
Www.111cn.net
Www.111cn.net
?>

The two types of output results are identical, so we will not talk about traversing multi-dimensional data. It is more convenient to use foreach for multi-dimensional data.

This site original tutorial, reproduced must be noted from the http://www.111cn.net/phper/php.html or study

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.