【发布时间】:2014-02-11 17:34:42
【问题描述】:
如果我在 PHP 中写了 for 循环
foreach($vertex['neighbours'] as $n_vertex)
是不是类似于下面Python中的for循环
for n_vertex in vertex['neighbors']:
在我使用 PHP 中的 While 循环时也是如此
while(!empty($my_queue))
是不是类似于下面Python中的while循环
while my_queue:
如果不是,那么在 Python 中的 for 和 while 循环在 PHP 中的正确版本是什么。
【问题讨论】:
-
两个例子都是正确的。对于后者,假设
my_queue是一个列表,只要my_queue不为空,它将评估为True。
标签: php python loops for-loop while-loop