将两个数组合并为单个内部json_encode for android

时间:2017-10-18 16:50:38

标签: php android arrays

我必须将两个数组合并到单个内部Json编码中。我的代码是,

// Controller

        $email = $this->input->get('email');
        $pass = $this->input->get('password');
        $enc_pass = 0;

        $get_pass = $this->select->selectData($email);

        if(!empty($get_pass)) {
            foreach($get_pass as $password)
                $enc_pass = $password['user_password'];

            $dec_pass = $this->encrypt->decode($enc_pass);

            if($pass == $dec_pass) {
                $details = array('tag' => 'login', 'status' => 'true');
                echo json_encode(array_merge($get_pass, $details));
            }
            else {
                $details = array('tag' => 'login', 'status' => 'false', 'error_msg' => 'Incorrect Email or Password');
                echo json_encode($details);
            }
        }
        else {
            $details = array('tag' => 'login', 'status' => 'false', 'error_msg' => 'Incorrect Email or Password');
            echo json_encode($details);
        }

// Model

public function selectData($email) {
    $query = $this->db->query('SELECT * FROM tbl_user WHERE email = "'.$email.'"');
    $count = $query->num_rows();

    if($count > 0)
        return $result = $query->result_array();
    else
        return 0;
}

现在上面代码的输出是,

{"0":{"user_id":"1","user_name":"Jithin Varghese","user_email":"jithinvarghese111@gmail.com","user_phone":"9947732296","user_status":"1"},"tag":"login","status":"true"}

必需的输出是,

{"user_id":"1","user_name":"Jithin Varghese","user_email":"jithinvarghese111@gmail.com","user_phone":"9947732296","user_status":"1","tag":"login","status":"true"}

如何获得所需的输出。我已经尝试了很多。如何实现这一点。

三江源。

0 个答案:

没有答案