$value) { $answer = new Answer(); $answer->id = trim($key); $answer->text = trim($value); if($key == intval($r['correct'])){$answer->correct = true;} $answers[] = $answer; } $data[] = array( id => trim($r['id']), question => trim($r['question']), points => trim($r['points']), answers => $answers ); } header('Content-type: application/json'); echo json_encode( $data ); ?>