- json_encode: documentation ( source)
- header: documentation ( source)
<?php
header('Content-Type: application/json');
function returnJSON (string $string, bool $success) {
exit(json_encode(['success' => $success, 'message' => $string])); //doesnt print anything
}
if ($someCondition)
returnJSON("This message is not printed...", false);