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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:58:03+00:00 2026-06-11T16:58:03+00:00

I have two arrays in php that contain custom class objects. One I iterate

  • 0

I have two arrays in php that contain custom class objects. One I iterate through in a while loop, using $h, and the other I access through another variable, $i, inside the while loop for comparison. I only increment $i within the parent loop if a certain condition is met, and there may be multiple copies of the same object within the array, which I need to skip over.

My code looks as follows:

$h = 0;
$i = 0
$j = 10; // Number determined elsewhere but statically entered for example purposes

while ($h < $j)
{
    if ($audits[$i]->id == $auditIDs[$h])
    {
        // Do Stuff...

        do
        {
            $i++;
        } while ($audits[$i]->id == $audits[$i+1]->id);
    }
    else
    {
        // Do stuff...
    }
    $h++;
}

If I replace the == comparison operator with === it still fails. Replace the do-while loop with a simple IF statement works, however.

if ($audits[$i]->id == $audits[$i+1]->id)
{
    $i++;
}

But that code does not allow for the possibility of more than one duplicate in the array, which may or may not occur, and I have to increment $i manually before calling the if statement (it must be incremented at least once if the previous if statement evaluates to true).

Can anyone shed some light into the situation? I appreciate the help!

class auditItem
{
    public $login;
    public $points;
    public $date;
    public $onTime;
    public $name;
    public $id;
    public $msg;

    function auditItem($login, $points, $date, $name, $id, $msg)
    {
        $this->login = $login;
        $this->points = $points;
        $this->date = $date;
        $this->name = $name;
        $this->id = $id;
        $this->msg = $msg;
    }
}
  • 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-11T16:58:05+00:00Added an answer on June 11, 2026 at 4:58 pm

    In PHP, the do-while loop has special behavior. It differs from a regular while loop in the fact that the first iteration is guaranteed to always run. In your code, $i has already been incremented by 1 before the comparison check, whereas, in the if statement, it has not.

    That’s the difference in the two blocks of code I noticed. You haven’t given enough information about the $audits array to provide a solid solution. Perhaps the the second index is out of bounds?

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

Sidebar

Related Questions

Lets say I have the following two PHP arrays that contain integers: $foo =
I'm using php with smarty. In php I have two arrays: $code = Array
I have some code that appears to merge the data from two arrays using
I have two PHP arrays. One contains a group name and another contains a
I have two files, one containing an array in PHP that is echo ed
I have a multi dimensional array in PHP. $f = array('one' => array(*doesntmatter*), two
I have converted an array to object data like this: <?php $myobject->data = (object)Array('zero','one','two');
I have two arrays, @names and @employees , that are filled with strings that
I have two arrays. I'd like to copy ranges of data from one of
I have two arrays and I post the arrays in one input; <input name='sistem[]'

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.