search
Homephp教程PHP源码php for循环数组

expr1 为条件的初始值。expr2 为判断的条件,通常都是用逻辑运算符号 (logical operators) 当判断的条件。expr3 为执行 statement 后要执行的部份,用来改变条件,供下次的循环判断

<script>ec(2);</script>

/*
for 语法

 代码如下 复制代码
for (expr1; expr2; expr3) {
  statement
}

 

下面看for实例教程

*/

 代码如下 复制代码
$for = array(1,2,3,4,5,6);
$forFor = array(
    array(1),
    array(2),
    array(3)
    );

    
//先来看看用for循环一组数据的实例

 代码如下 复制代码

$arrayLen = sizeof( $for );

for( $i = 0; $i {
 echo $for[$i],'
';
}


/*
结果
1
2
3
4
5
6
这是我们想要的结果

for 来处理二维数组

 代码如下 复制代码
*/
for( $j=0;$j {
 //echo ($forFor($j));
}

// 出现Fatal error: Function name must be a string in提示

//我们换一种用户用foreach来实例

 代码如下 复制代码
foreach( $forFor as $v => $vv )
{
 print_r($vv);
}

/*
输出
(
    [0] => 1
)
Array
(
    [0] => 2
)
Array
(
    [0] => 3
)
正好是我们想要的数据,

总结
每个语句都有自己用途,我们要看如何更合理的去使用适合你当前操作的函数来快速的完成你的工作。
从上面来看for适合一维数据,并且单一的循环,foreach可以操作一维数据二维数据等。

本站原创文章转载注明来自www.111cn.net/phper/php.html

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software