如果为空则删除数组

I have an array of errors for file upload. It display errors message if the upload went wrong. But if the array is getting no errors, it display "Array" on my view.

How to remove the "Array" if it's empty?

My controller:

if (!is_null($avatar) && !empty($avatar)) {
            if ($_FILES && $_FILES['avatar']['name'] !== "") {
                if (!$this->upload->do_upload('avatar')) {
                    $data['errors'] = array('error' => $this->upload->display_errors());
                } else {
                    $image = $this->upload->data();
                    $avatar = $image['file_name'];
                }
            }
        }
$this->load->view('auth/edit_profile_form', $data);

My view:

<div class="errors">
<?php echo $errors; ?>
</div>

Check the amount of entries on your errors array:

echo (count($errors) > 0 ? implode("<br>", $errors) : '');

This checks if the $errors variable is set. If $errors['error'] it contains something, the <div class="errors"> will be printed.

<?php
if ($errors['error']) {
     echo '<div class="errors">'.$errors['error'].'</div>';
}
?>

In your view:

<?php if ($errors['error']): >
<div class="errors">
  <?php echo $errors['error']; ?>
</div>
<?php endif; >

In your view you want to do

<?php if(is_array($errors) && !empty($errors)) { ?>
    <div class="errors">
        <?php foreach($errors as $error) { ?>
            <?php echo $error; ?>
        <?php } ?>
    </div>
<?php } ?>

This checks to see if there is anything in the array and the loop through each item in the array and echo's it