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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:16:11+00:00 2026-05-27T04:16:11+00:00

I am facing a very weird behaviour. I have the $answer_styles array with some

  • 0

I am facing a very weird behaviour. I have the $answer_styles array with some data, which I need to manipulate:

foreach($answer_styles as $id => &$answer_style){
    $answer_style['id'] = $id;
    $answer_style_names[$id] = $answer_style['name'];
}
array_multisort($answer_style_names, SORT_ASC, SORT_STRING, $answer_styles);

and then I save it to another variable, for later use: $stats['answer_styles'] = $answer_styles;

Now, I need to step into the original array using a foreach loop. I’ve done this:

debug($stats['answer_styles']);
foreach($answer_styles as $answer_style){
    debug($stats['answer_styles']);
        ...

The problem is that the first debug shows the data it should show, but the second debug shows the last record overwritten by the first one (so, from 1, 2, 3, 4 it now shows 1, 2, 3, 1). Why is this happening since I don’t manipulate the $stats array, but the $answer_styles one?

EDIT

This is the output for the first, respectively, the second debug:

app/models/test.php (line 299)

Array
(
[0] => Array
    (
        [name] => Alege din 3
        [count] => 8
        [correct] => 2
        [id] => 3
    )

[1] => Array
    (
        [name] => Alege din 4
        [count] => 3
        [correct] => 2
        [id] => 2
    )

[2] => Array
    (
        [name] => Alege din 6
        [count] => 7
        [correct] => 3
        [id] => 4
    )

[3] => Array
    (
        [name] => Scrie raspunsul
        [count] => 2
        [correct] => 1
        [id] => 1
    )

)


app/models/test.php (line 301)

Array
(
[0] => Array
    (
        [name] => Alege din 3
        [count] => 8
        [correct] => 2
        [id] => 3
    )

[1] => Array
    (
        [name] => Alege din 4
        [count] => 3
        [correct] => 2
        [id] => 2
    )

[2] => Array
    (
        [name] => Alege din 6
        [count] => 7
        [correct] => 3
        [id] => 4
    )

[3] => Array
    (
        [name] => Alege din 3
        [count] => 8
        [correct] => 2
        [id] => 3
    )

)
  • 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-27T04:16:11+00:00Added an answer on May 27, 2026 at 4:16 am

    This is because you are keeping reference to array element with this expression &$answer_style and using same variable name in second loop.

    do:

    unset($answer_style);
    

    after first loop and things will be fixed.

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

Sidebar

Related Questions

I am facing a very regular scenario. I have an NSArray which has object
I am facing this very weird problem, I have created a custom UITableViewCell on
In my 2nd ASP.NET MVC project I'm facing a very weird problem: when I
I am facing a very strange issue. I have a SharePoint webpart that displays
I have an upload system ready, however I might be facing a very high
I am facing a very strange problem. I have a grid and when i
We are facing a very weird situation using Visual Studio 2005: There is a
I need to create a very long string in a program, and have been
I'm facing a path finding problem in which I have to find every possible
I am facing very weird problem, i made an web application for my client,

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.