Does "break continue" exist in PHP? -


for context question please see recent post. in function below, break continue allow me omit last if condition. (see comment in inner loop)

function strposhypothetical($haystack, $needle) {      $haystacklength = strlen($haystack);     $needlelength   = strlen($needle);//for question let's assume > 0      $pos = false;      for($i = 0; $i < $haystacklength; $i++) {         for($j = 0; $j < $needlelength; $j++) {             $thissum = $i + $j;             if (($thissum > $haystacklength) ||                  ($needle[$j] !== $haystack[$thissum]))                    break;              // if "break continue" omit              // if ($j === $needlelength)              // below , write $pos = $i; break;                }         if ($j === $needlelength) {             $pos = $i;             break;         }     }     return $pos; } 

i have seen similar posts such this 1 don't quite answer question. not want refactor function above. don't need break 2 nor continue 2. note break 2 not work in inner loop because necessary iterations in outer loop missed. continue 2 fails because inner loop needs iterate end of needle. break continue possible in php?

note have tried , got fatal error assume either answer "no" or implemented incorrectly.

note 2 "break continue" mean break inner loop continue outer

there continue (skip)

<?php   while (list($key, $value) = each($arr)) {     if (!($key % 2)) { // skip members        continue;     }     do_something_odd($value); }  ?> 

http://php.net/manual/en/control-structures.continue.php

for($i = 0; $i < $haystacklength; $i++) {     for($j = 0; $j < $needlelength; $j++) {         $thissum = $i + $j;         if (($thissum > $haystacklength) ||              ($needle[$j] !== $haystack[$thissum]))              continue;        }     if ($j === $needlelength) {         $pos = $i;         break;     } } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -