The code below brings me an array of images. I have 15 fields: "img1", "img2", "img3" and so on.
Sometimes not all the fields have data. I don´t want to include them into the array. Is there a way to keep these empty fields outside the array?
<?php
include_once 'db_connect.php';
$i_id = $_POST["imovel_id"];
$sql = "SELECT * FROM iMoveis WHERE imovel_id='$i_id'";
$result = mysqli_query($mysqli, $sql);
$response = array();
$images = array();
while($row = mysqli_fetch_assoc($result)){
$images[] = array('images' => $row['img1']);
$images[] = array('images' => $row['img2']);
$images[] = array('images' => $row['img3']);
$images[] = array('images' => $row['img4']);
$images[] = array('images' => $row['img5']);
$images[] = array('images' => $row['img6']);
$images[] = array('images' => $row['img7']);
$images[] = array('images' => $row['img8']);
$images[] = array('images' => $row['img9']);
$images[] = array('images' => $row['img10']);
$images[] = array('images' => $row['img11']);
$images[] = array('images' => $row['img12']);
$images[] = array('images' => $row['img13']);
$images[] = array('images' => $row['img14']);
$images[] = array('images' => $row['img15']);
}
$response['posts'] = $images;
echo json_encode($response, JSON_UNESCAPED_SLASHES);
?>