【问题标题】:how can I keep looping through an array until every element is moved to another array?如何继续循环遍历数组,直到每个元素都移动到另一个数组?
【发布时间】:2015-07-30 23:46:18
【问题描述】:

我是 PHP 新手,但我已经有一个难题。

我有一个这样的数组:

$test = array("00000","00001","00011","00111","00101","00110","00110", etc (so it is unordered...)

现在:

我想检查第一个位置和第二个位置。如果 Levensthein

之后,接下来的 2 个值应该相互检查...

那么你怎么能一直循环遍历一个数组呢?

【问题讨论】:

标签: php arrays loops


【解决方案1】:

保持循环遍历数组直到它为空的最简单方法是有两个循环:一个循环直到数组为空,另一个循环遍历数组中剩余的每个元素。

只需确保您的代码确保数组最终会变为空,否则它将陷入无限循环。

while(count($array)) { 
  foreach( $array as $element ) {
    // your code goes here
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    • 2018-04-07
    • 1970-01-01
    • 2018-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多