0

here I need to remove the same week id object array from my main array in PHP

[{"week_id":""},
{"week_id":"23","location_schedule":"Tuesday","location_date_from":"10\/18\/2022 4:30 PM"},
{"week_id":"23","location_schedule":"Tuesday","location_date_from":"10\/18\/2022 4:30 PM"},
{"week_id":"24","location_schedule":"Tuesday","location_date_from":"10\/25\/2022 3:30 PM"},
{"week_id":"24","location_schedule":"Tuesday","location_date_from":"10\/25\/2022 3:30 PM"}]
$weeksArray = array(array("week_id"=>""));
$i=0;
foreach($orderweek as $weeks)
{
    
        $weeksArray[]=[
        'week_id'=>$weeks['week_id'],
        'location_schedule'=>$weeks['location_schedule'],
        'location_date_from'=>$weeks['location_date_from']
    ];
    
    echo "<br>";
    
    // }
    $i++;
}
// $weeksArray = array(array("week_id"=>"25"));
echo json_encode($weeksArray);
1
  • What have you tried so far? Where are you stuck? Also, as far as I see, there are no objects in your array, but solely sub arrays Commented Oct 11, 2022 at 6:45

1 Answer 1

-1

You already tried array_unique()?

If not Put array_unique($weeksArray, SORT_REGULAR) before json_encode

Here is documentation. https://www.php.net/manual/en/function.array-unique.php

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.