certianオブジェクトの子孫をすべて返し、すべてをJSONにエンコードすることになっている関数に問題があります。現在は機能していますが、JSONエンコードに多数のnullがあり、それらをスクラブするためarray_filter()
のforeach
ループを試しましたが、どちらも機能しませんでした。
findChildren($conn, $topic);
$data = array();
function findChildren($conn, $topic) {
$rst = $conn->query("SELECT topicID, topicTitle, topicParentID, topicDeleted FROM tbl_topics WHERE topicParentID = $topic");
while ($row = $rst->fetch_assoc()) {
if ($row['topicDeleted'] == 0) {
//$data[] = htmlentities($row, UTF-8);
if($row != '') {
$data[] = $row;
}
findChildren($conn, $row['topicID']);
}
}
echo json_encode( $data );
}
どんな助けでも素晴らしいでしょう。ありがとう。