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);
Nick
  • 138,499
  • 22
  • 57
  • 95
Jay Parmar
  • 111
  • 4
  • 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 – Nico Haase Oct 11 '22 at 06:45

1 Answers1

-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