Home  >  Article  >  Backend Development  >  PHP关于条件判断的问题

PHP关于条件判断的问题

WBOY
WBOYOriginal
2016-06-06 20:25:051078browse

<code><?php $contact=array('id'=>1,'姓名'=>'高某','公司'=>'A公司');
    while(list($a,$b)=each($contact)){
    echo $a."&nbsp".$b.'<br>';
}
    ?>
在这段代码中,while的条件判断我不是很明白,(为什么直接写list($a,$b)=each($contact)就行),条件是根据函数的返回值来判断还是根据什么??</code>

回复内容:

<code><?php $contact=array('id'=>1,'姓名'=>'高某','公司'=>'A公司');
    while(list($a,$b)=each($contact)){
    echo $a."&nbsp".$b.'<br>';
}
    ?>
在这段代码中,while的条件判断我不是很明白,(为什么直接写list($a,$b)=each($contact)就行),条件是根据函数的返回值来判断还是根据什么??</code>

each — 返回数组中当前的键/值对并将数组指针向前移动一步,如果内部指针越过了数组的末端,则 each() 返回 FALSE。所以while就退出了。
附上文档:http://php.net/manual/zh/function.each.php

请参考 PHP 中关于 each 的说明:

http://php.net/manual/zh/function.each.php

PHP关于条件判断的问题

PHP关于条件判断的问题

= 是赋值符,把右边的赋值给左边。while 判断左边的值是否为真

http://php.net/manual/zh/function.each.php

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