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 6056335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:21:54+00:00 2026-05-23T08:21:54+00:00

Ok now its weird but when i print the array in the test1 function

  • 0

Ok now its weird but when i print the array in the test1 function its prints all the arrays but when it display it from the test2 function its displays only the last records can anyone tell me where i am wrong?

class template{
    private $block = array();
    private $page;

    public function test1($data){
        foreach($data as $k => $v){
            $this->block[$k] = $v;
        }
        print_r ($this->block);
    }

    public function test2(){
        print_r ($this->block);
    }
}

$template = new template();

while($row1 = mysql_fetch_assoc($bbcat)){
    $template->test1(array("TIT" => $row1['title']));
    while($row2 = mysql_fetch_assoc($bbscat)){
        $template->test1(array("FTIT" => $row2['title']));

    }
}
  • 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-23T08:21:55+00:00Added an answer on May 23, 2026 at 8:21 am

    It’s because the foreach loop is looping and setting $this->block. So once it’s done the last iteration $this->block is now set to the data in the last loop.

    CLARIFICATION

    Every loop we do in the foreach loop is setting $this->block to some new data. Once the last iteration of the loop has finished we are given the data which was outputted in the final loop.

    Does that make more sense?

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

Sidebar

Related Questions

I have been building IMO a really cool RIA. But its now close to
Is the edit control I'm typing in now, with all its buttons and rules
Right now I am trying to call my model, and spit out its results
My project has collected CSS entropy (unused classes) during its course of development. Now
Weird question I think its more of I am not sure what it is
I'm trying to print characters in the console at specified coordinates. Up to now
I've a weird problem with my application, its memory usage goes up a few
I got my inv finally working! :D But, you know... now... it's dumb. I
Now that it's clear what a metaclass is , there is an associated concept
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really

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.