JSON parser for PHP v2

$return['person'] = array('firstName' => 'John', 'lastName' => 'Smith');
$return['result'] = 'success';

// output correct header
$xhr = isset($_SERVER['HTTP_X_REQUESTED_WITH']) and (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
header('Content-Type: ' . ($xhr ? 'application/json' : 'text/plain'));

echo json_encode($return);

?>