PHP에서 null 값을 제거하려면 array_filter()를 사용하십시오. 배열 값을 필터링합니다. 다음이 우리의 배열이라고 가정해 봅시다 -
$studentDetails = array("firstName" => "John", "lastName"=> null); echo "The original value is=";print_r($studentDetails);
array_filter()로 필터링합시다 -
$result = array_filter($studentDetails);
예시
<!DOCTYPE html> <html> <body> <?php $studentDetails = array("firstName" => "John", "lastName"=> null); echo "The original value is="; print_r($studentDetails); $result = array_filter($studentDetails); echo "</br>"; echo "After removing null part,the result is="; print_r($result); ?> </body> </html>
출력
The original value is=Array ( [firstName] => John [lastName] => ) After removing null part,the result is=Array ( [firstName] => John )