0

I have 52 weeks array's and each week array has a sub array with 9 values. now I need to add a value 0 at the begin of each array and every next week I need 1 value more.

For example (notice that the 0-8 will be in a for loop)

    $vruchtzettings_week["week1"][0-8] = 1, 2, 3, 4, 5, 6, 7, 8, 9
    $vruchtzettings_week["week2"][0-8] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
    $vruchtzettings_week["week3"][0-8] = 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
    $vruchtzettings_week["week4"][0-8] = 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
8
  • 7
    Yes, you need to be using a for loop. Commented Jan 15, 2014 at 18:07
  • Fix your question title please. In a list of questions it tells me nothing about this question (other than, frankly, to avoid it...) Commented Jan 15, 2014 at 18:08
  • it's php, there is no way. Commented Jan 15, 2014 at 18:09
  • eum a good link to find answers to this question: google.com Commented Jan 15, 2014 at 18:09
  • just write down loops for each statement (sum) and then you'll see how to write second loop. Commented Jan 15, 2014 at 18:12

1 Answer 1

3

Though I can't really test it, I believe this would do it for you. What you're doing is really convoluted.

$week = 1;
while ($week <= 52) {
  $sum = 0;

  for ($sub = 0; $sub < 9; $sub++, $week++;) {
    $totaal_vruchtzetting_week[$week] = $totaal["week$week"][$sub] + $sum;
    $sum += $totaal["week$week"][$sub];
  }
}

Like I said, you will probably have to tweek this a little. But it will get you started.

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

Comments

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.