I have one array using i want to make my json response but i am not able do this:
print_r($exist_email);
Array
(
[user_id] => 3
)
I tried like this
$response_array['status']='Exist User';
$response_array['message']='Email already exists.';
$response_array['data']=$exist_email;
$this->response($this->json($response_array), 200);
public function response($data,$status=200){
$this->_code = ($status)?$status:200;
$this->set_headers();
echo $data;
exit;
}
protected function json($data){
if(is_array($data)){
return json_encode($data);
}
}
I am getting response
{
"status": "Exist User",
"message": "Email already exists.",
"data": {
"user_id": "3"
}
}
My expected output
{
"status": "Exist User",
"message": "Email already exists.",
"data": [
{
"user_id": "3"
}
]
}