0

I've got this cycle:

   $diffe = $differenz*7;  
    $diff = 0; 
    $n = 0;
    $an = $anzahl-1;
    $z = 0;
    $plus = $periode;
    $oarray = array();
    $sarray = array();
    $parray = array();
    $h = 0;

    while ($n < $ortcount) {
    foreach ($ortearray as $o) {
    $oarray[] = $o;
    }
    $sarray[] = get_start_dates($star, $diff, $wochearray); 
    $diff += $diffe;

    while ($h < $ortcount) {
    $helpingstring= join(";",$sarray[$h]);
    echo $h;
    $sarrayhelp = explode(";", $helpingstring);

    while ($z < $an) {

    foreach ($sarrayhelp as $s) {         
    $parray[] = plustime($s, $plus);        

    }
    $plus = $plus+$periode;
    $z++;

    }
    $h++;
    }

    $n++;

    }

and need the following:

every "subarray" of the multidimensional array "$sarray[]" should be progressively processed by the plustime() function and results should be saved to "$parray[]".

At this time, only the first subarray of "$sarray[]" is being processed.

Any help would be greately appreciated. Please help!

1
  • 1
    I think the first step is that you learn how to properly indent code. Commented Sep 1, 2012 at 17:18

1 Answer 1

2

Make recursive function:

function process(&$parray, $array, $plus){
  foreach($array as $s) {
    if(is_array($s)) {
      // this is subarray
      process($parray, $s, $plus);
      continue ;
    }
    $parray[] = plustime($s, $plus);
  }
}

.....
while ($z < $an) {
  process($parray, $sarrayhelp, $plus);
  ..

Please mind, bad indent and short variables ($a, $az,$n, $an, $h, $z, $parray, $oarray, $diff, $diffe) makes your code very to difficult maintance and understand by others.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, yes! That's it. Thanks very much. Sorry, I am a beginner and perhaps I also made the ident worse when copying the code to this forum.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.