-2

I'm newby in PHP but I allready have a difficult question.

I have an array which is like this:

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

now:

I'd like to check the first position with the second. if the Levensthein is <=1 then that value should stay in place and if it is not it should either. move to the last position in the array... or move to another array (i don't know what is best)

after that, the next 2 values should be checked with eachother...

so how can you keep looping through an array?

José Ricardo Pla
  • 1,043
  • 10
  • 16
tijnn
  • 406
  • 1
  • 8
  • 24

1 Answers1

2

The easiest way to keep looping over an array until it is empty is to have two loops: one that loops until the array is empty and inside it one that loops over each element remaining in the array.

Just make sure that your code ensures that the array will go empty eventually or it'll be trapped in an infinite loop.

while(count($array)) { 
  foreach( $array as $element ) {
    // your code goes here
  }
}
Erik
  • 3,598
  • 14
  • 29