1) Recheck array is empty or null
Link: https://www.geeksforgeeks.org/how-to-check-whether-an-array-is-empty-using-php/
Cách 1:
<?php
// Declare an array and initialize it
$non_empty_array = array('URL' => 'https://www.geeksforgeeks.org/');
// Declare an empty array
$empty_array = array();
// Condition to check array is empty or not
if(!empty($non_empty_array))
echo "Given Array is not empty <br>";
if(empty($empty_array))
echo "Given Array is empty";
?>
Cách 2
<?php
// Declare an empty array
$empty_array = array();
// Function to count array
// element and use condition
if(count($empty_array) == 0)
echo "Array is empty";
else
echo "Array is non- empty";
?>
Cách 3:
<?php
// Declare an empty array
$empty_array = array();
// Use array index to check
// array is empty or not
if( sizeof($empty_array) == 0 )
echo "Empty Array";
else
echo "Non-Empty Array";
?>
2) Removing key that has a null value in an array
Tiếp theo là phần khác (update Mon 13 Dec 2021) Xoá key và value nếu value bằng null
$json = json_encode($complexObject);
echo preg_replace('/,\s*"[^"]+":null|"[^"]+":null,?/', '', $json);
Mình thấy kiểu trên khá hay