0

I have an arrayof objects like

[
 null,
 {
   "list_type": 1,
   "list_item": {
       "id": 21,
       "name":"aaa"
   }
 },
null,
null,
 {
   "list_type": 0,
   "list_item": {
       "id": 24,
       "name":"bbb"
   }
 }
]

I want to remove the null values from this. I have used array_filter() but it doesn't work. How can I achieve this?

Jyothi
  • 53
  • 8
  • *"I have used array_filter() but it doesn't work"* Show us, please – Cid Mar 07 '22 at 11:28
  • first trim the values using array_map("trim", array_name); and then use array_filter(); – atomankion Mar 07 '22 at 11:47
  • error occurs on using array_map("trim",$listItems); " Error: Object of class Illuminate\Http\Resources\Json\AnonymousResourceCollection could not be converted to string" – Jyothi Mar 07 '22 at 13:21

0 Answers0