将值发回给ajax

Problem, is, if in x.php file I do following:

print_r($data->name);

then I get in Ajax call console.log(data); (Right data), but if I don't do print_r, I get null. I dont really want to print_r($data) in x.php, I just want to pass the value (without printing on screen) back to ajax function, so console.log($data) would show correct data and then manipulate it there with some html. How can I do this?

header('Content-Type: application/json');
echo json_encode($array);
exit();