0

I have a PHP array which has some values that am storing to an API,, I want to show the field that has a value and omit the others but aint sure how to write the logic in PHP,,

~ Kindly assist?

array:5 [
  "child1Dob" => "2018-11-07",
  "child2Dob" => null,
  "child3Dob" => null,
  "child4Dob" => null,
  "child5Dob" => null,
]
Patweb
  • 133
  • 1
  • 10

2 Answers2

1

You can use array_filter to only keep the values that are not Null. Try like this.

array_filter($array);
Igor Carvalho
  • 668
  • 5
  • 19
0

Try this

$b = array_filter($a, function($k) { return $k!=null; });

Working example here.

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345