How to return array in php ? Acctually I want to return whole value of $x[] insted of last index of $x[].Please help me : How to return array in php ? Acctually I want to return whole value of $x[] insted of last index of $x[].Please help me...  


<?php
    
    function top() {
        require './php/connection.php';
        $sql = "SELECT * FROM tbl_add";
        $query = mysqli_query($connect, $sql);
        $n = 0;
        while ($result = mysqli_fetch_assoc($query)) {
            $a[$n] = $result['add_id'];
            $n = $n + 1;
        }
        $n = $n - 1;
        for ($j = 0; $j < $n; $j++) {
            for ($i = 0; $i < $n - 1 - $j; $i++) {
                if ($a[$i] > $a[$i + 1]) {
                    $tmp = $a[$i];
                    $a[$i] = $a[$i + 1];
                    $a[$i + 1] = $tmp;
                }
            }
        }
        for ($i = 0; $i <= $n; $i++) {
            echo $a[$i] . '<br>';
        }
        $j = 1;
        for ($i = 0; $i <= 5; $i++) {
            $r = $a[$i];
    
            $sql = "SELECT * FROM tbl_add WHERE add_id='$r'";
            $query = mysqli_query($connect, $sql);
            $result = mysqli_fetch_assoc($query);
            if ($result) {
                $x[] = $result['mail'];
                return $x[];
            }
        }

    }
    
    ?>