- json_encode: documentation ( source)
<?php
/* String to print for an error where a parameter is missing from the post */
const ERROR_MISSING_PARAM = "10000";
$errors = array();
$number_of_errors = 0;
function addError($error, $variable){
$errors[$variable] = $error;
$number_of_errors = count($errors);
}
function printToJson(){
return json_encode($this->errors);
}
addError(ERROR_MISSING_PARAM, 'name');
echo $number_of_errors . "\r\n";
echo printToJson();