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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:44:36+00:00 2026-06-01T11:44:36+00:00

I have this type of associative array. Array ( [0] => Array ( [bookedArea]

  • 0

I have this type of associative array.

Array
(
 [0] => Array
    (
        [bookedArea] => Comp Pool
        [laneBooked] => 1
        [paidBy] => Edmonton Aurora Synchronized Swim Club
        [startTime24hr] => 16:00
        [finishTime24hr] => 18:00
    )

 [1] => Array
    (
        [bookedArea] => Comp Pool
        [laneBooked] => 2
        [paidBy] => Edmonton Aurora Synchronized Swim Club
        [startTime24hr] => 16:00
        [finishTime24hr] => 18:00
    )

 [2] => Array
    (
        [bookedArea] => Comp Pool
        [laneBooked] => 3
        [paidBy] => Keyano Swim Club
        [startTime24hr] => 16:00
        [finishTime24hr] => 18:00
    )
)

I would like to make a new array removing similar entries depending on several associations. startTime24hr, finishTime24hr bookedArea & paidBy if all 4 aren’t the same then it shouldn’t be removed. Plus I would like to capture the first and last lanes in the new associative array.

Array
  (
    [0] => Array
     (
        [bookedArea] => Comp Pool
        [firstLaneBooked] => 1
        [lastLaneBooked] => 2
        [paidBy] => Edmonton Aurora Synchronized Swim Club
        [startTime24hr] => 16:00
        [finishTime24hr] => 18:00
     )
    [2] => Array
     (
        [bookedArea] => Comp Pool
        [firstLaneBooked] => 3
        [lastLaneBooked] => 3
        [paidBy] => Keyano Swim Club
        [startTime24hr] => 16:00
        [finishTime24hr] => 18:00
     )
  )

I found this which would help me filter with only one association. However I need 3 more.

$copy = $array; // create copy to delete dups from the array you wish to filter from
$newFilteredArray = array(); // new filtered array.
$item1 = 'startTime24hr'; // the association you want to filter with.
for( $i=0; $i<count($array); $i++ ) {
    if ( in_array( $array[$i][$item1], $newFilteredArray ) ) {
        unset($copy[$i]);
    }
    else {
        $newFilteredArray [] = $array[$i][$item1]
    }
}
print_r($copy);

Edit —-
Thank you Alexander for helping me get the iterations correct.

I have been struggling with inserting into my filtered array the start and finish lanes. I have commented out my attempts to make it work. When its uncommented I get: Notice: Undefined index: startTime24hr and it seems like its in some infinite loop.
But if you comment my stuff no Notices. Can anyone help with this?
function array_push_assoc($array, $key, $value){
$array[$key][] = $value;
return $array;
}

$CPfilteredArray = array();
$lanes = 0;
for($i = 0; $i < count($compPoolArray); $i++) {
  $add = true;
  // $lanesAdded = false;
  // $lanes = $lanes + 1;
  // $startLane = $compPoolArray[$i]["laneBooked"];
  for($j = 0; $j < count($CPfilteredArray); $j++) {
    if(($compPoolArray[$i]["startTime24hr"] === $CPfilteredArray[$j]["startTime24hr"])
        && ($compPoolArray[$i]["finishTime24hr"] === $CPfilteredArray[$j]["finishTime24hr"])
        && ($compPoolArray[$i]["bookedArea"] === $CPfilteredArray[$j]["bookedArea"])
        && ($compPoolArray[$i]["paidBy"] === $CPfilteredArray[$j]["paidBy"])) {
            $add = false;
            // $lanes = $lanes + 1;
            // $lanesAdded = True;
    }
  }
    if($add) {
        $CPfilteredArray[] = $compPoolArray[$i];
        // if ($lanesAdded){
        //     $lastLane = $startLane + $lanes;
        //     $CPfilteredArray[$i] = array_push_assoc($CPfilteredArray, 'firstLane', $startLane);
        //     $CPfilteredArray[$i] = array_push_assoc($CPfilteredArray, 'lastLane', $lastLane);
        // }
        // else {
        //     $CPfilteredArray[$i] = array_push_assoc($CPfilteredArray, 'firstLane', $startLane);
        //     $CPfilteredArray[$i] = array_push_assoc($CPfilteredArray, 'lastLane', $startLane);
        // }
    }
}
  • 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-01T11:44:37+00:00Added an answer on June 1, 2026 at 11:44 am

    Two loop cycles do the job.

    $filteredArray = array();
    for($i = 0; $i < count($array); $i++) {
      $add = true;
      for($j = 0; $j < count($filteredArray); $j++) {
        if(($array[$i]["startTime24hr"] === $filteredArray[$j]["startTime24hr"])
            && ($array[$i]["finishTime24hr"] === $filteredArray[$j]["finishTime24hr"])
            && ($array[$i]["bookedArea"] === $filteredArray[$j]["bookedArea"])
            && ($array[$i]["paidBy"] === $filteredArray[$j]["paidBy"])) {
           $add = false;
        }
      }
      if($add) $filteredArray[] = $array[$i];
    }
    

    The resulting array called $filteredArray contains the filtered elements.

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

Sidebar

Related Questions

I have a PHP multidimensional associative array with the following structure: Fields: TYPE -
I have this type of data: entity, account, month1, month2, ..., month12 abc, 2000.02,
i have this simple type from an external webservice: <xsd:element name=card_number maxOccurs=1 minOccurs=1> <xsd:simpleType>
I have this JavaScript: var Type = function(name) { this.name = name; }; var
Lets say have this immutable record type: public class Record { public Record(int x,
I have this mysql table called comments which looks like this: commentID parentID type
I have this method call: public DataTemplate Create(Type type, string propertyName) { string str
I have this below code and it work fine header (content-type: text/xml); $xml =
I have a member pointer with this type: const TopState<TestHSM>* state_; state_ is of
I have a for cycle that iterates over an associative array. foreach entry i

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.