Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4614718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:44:21+00:00 2026-05-22T01:44:21+00:00

<?php // initial value $week = 50; $year = 2001; $store = array(); do

  • 0
<?php
// initial value

$week = 50;
$year = 2001;
$store = array();
do
  {
  $week++;
  $result = "$week/$year";
  array_push($store,$result);
  if($week == 53){
    $week = 0;
    $year++;//increment year by 1
    }
    continue;
  }
// End of Loop
while ($result !== "2/2002");

?>

print_r($store);

result want return will be

array("51/2001", "52/2001", "01/2002", "02/2002");

What is my problems by using while using do..while ,continue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:44:22+00:00Added an answer on May 22, 2026 at 1:44 am
    • Your arguments to array_push are the wrong way around. Read the manual entry for functions you use. Turn on warnings on your server; running this in codepad showed me the problem immediately. [Edit: You have now quietly fixed that in your question.]
    • You also have a typo: $i instead of $week.
    • Finally, you test against “02/2002”, but for that month the string will be “2/2002”.

    Fixed code (live demo):

    <?php
    // initial value
    
    $week = 50;
    $year = 2001;
    $store = array();
    do
      {
      $week++;
      $result = "$week/$year";
      array_push($store, $result);
      if($week == 53){
        $week = 0;
        $year++;//increment year by 1
        }
        continue;
      }
    // End of Loop
    while ($result !== "2/2002");
    ?>
    

    In general, I’d recommend against loops like this. As you’ve discovered, your code is very fragile because you’re testing for just one very specific value, and if that value is not precisely correct you get an infinite loop.

    Instead, consider comparing $week and $year separately and numerically:

    while ($week < 2 && $year <= 2002)
    

    Next time please include in your question the output that you are seeing, as well as the output that you want to see. It’ll save us time in reproducing your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to the world of PHP frameworks and, after some initial investigation, came
PHP's explode function returns an array of strings split on some provided substring. It
I have the following code: <select name=to class=combo value=' <?php if(isset($_POST['reply'])) { echo <option
I am trying to have a textfield with an initial value, where if you
In php is there a function to increment the values of subsequent values twice(*2)
I'd like to store an additional column in a table as a 'sort value',
I've tried to port the following sum in a php for loop this way:
Initial javascript to get a string/array: <script type=text/javascript> $(document).ready(function() { $(#table).tableDnD({ onDrop: function(table, row){
Is there anyway using ModRewrite to achieve the following: Initial URL: http://example.com/page?value=test Rewirted URL:
I have a very simple PHP form, which shows a checkbox, and will store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.