在数组递归PHP和MYSQL中对数组进行排序

时间:2018-10-26 16:04:33

标签: php mysql symfony sorting recursive-datastructures

This is my DB table IMAGE

  1. I Have This code but, the result is this:

    array:2 [▼ 3 => array:1 [▼ 1 => [] ] 4 => array:1 [▼ 5 => array:1 [▼ 6 => array:1 [▼ 7 => [] ] ] ] ]

  2. But i need organize the code like this:

    array:[

    0 => 3, 1 => 1, 2 => 4, 3 => 5, 4 => 6, 5 => 7

    ]

// actually the parameter id is the session user

    public function misSubordinados($id){

    $conn = $this->getEntityManager()->getConnection();
    $sql = 'SELECT s.id_usuario  FROM `sy_supervisores_asesor` AS s
            WHERE s.id_supervisor IN (' . implode(',', [$id]) . ')';
    $stmt = $conn->prepare($sql);
    $stmt->execute();

    $total = array();

    $result = $stmt->fetchAll();

    if(count($result) > 0) {

        foreach ($result as $key => $value) {
                $total[$value['id_usuario']] = $this->misSubordinados($value['id_usuario']);  
        }

    }

    return $total;

    } 

0 个答案:

没有答案