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

  • SEARCH
  • Home
  • 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 9242197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:31:59+00:00 2026-06-18T08:31:59+00:00

I have this piece of code foreach($mnthArrPtrn as $m => $mn) { if(!isset($catName)) {

  • 0

I have this piece of code

foreach($mnthArrPtrn as $m => $mn)
{   
    if(!isset($catName)) {
        $catVals = array();      
        $prevCat = $catName = $pntChrtQry[0]['CAT']['categoryname']; 
        $pntVals .= '{name:'.$catName.',data:[';
    }else if($prevCat != $catName) {
        $prevCat = $catName;
        $catVals = array(); 
        $pntVals .= '{name:'.$catName.',data:[';
    }     
    foreach($pntChrtQry as $key => $val){
        $catName = $val['CAT']['categoryname'];
        if($prevCat != $catName){
            continue 2;
        }
        echo '<br />$m::'.$m; 
        echo '<br />$mn::'.$mn;
        echo '<br />$val::'.$val[0]['MNTH'];
        if($m == $val[0]['MNTH'] || $mn == $val[0]['MNTH']){
            $catVals[] = $val[0]['total'];
        }
    }
    pr($catVals);
    if(!isset($catName)){
        $pntVals .= ']},';
    }
    $catName = $val['CAT']['categoryname'];
}

1st loop iterates over a months array which are joined as a key value pair.
What I am doing here is on getting a new catName I continue the internal loop but at the same time I want to restart loop 1 with $prevCat,$catName still preserving their values.
Is this possible? Sorry If this is a silly question.

I tried converting the first one to a while statement and use a reset then but It didn’t help me.

  • 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-06-18T08:32:00+00:00Added an answer on June 18, 2026 at 8:32 am

    Something like this will allow you to arbitrarily restart a loop:

    while (list($key, $value) = each($mnthArrPtrn)) {
        if ($needToRestart) {
            reset($mnthArrPtrn);
        }
    }
    

    See more here.

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

Sidebar

Related Questions

I have this piece of code: int i = 0; foreach(var tile in lib.dic.Values)
Let's suppose I have this piece of code. foreach(string value in myList) { string
I have this piece of code: foreach (ListItem item in lbUnassigned.Items) { if (item.Selected)
I have this piece of code <ul> <?php $categories = get_categories('include=9,4,5,6,7,8,3&hide_empty=0'); foreach ($categories as
I have this piece of code: $xpath = new DOMXPath($dom); foreach ($xpath->query(//text()) as $q)
I have this piece of code in a function. I want to print the
I have this piece of code: public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener listener) {
I have this piece of code: @Entity @Table(name = MOVERS) public class MOVers implements
I have this piece of code for my images, so the opacity can lower
I have this piece of code, <div id=event style=display:none;> <!-- initially hidden --> <div

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.