saveAnswer( $_POST['user'], $_POST['ans'] ); $questID_arr = Question::getList( $quiz->getID() ); $index_int = array_search( $quest->getID(), $questID_arr ); $index_int++; $nextQuest = new Question( $questID_arr[ $index_int ] ); $ans_arr = $nextQuest->getAnswers(); $data_arr = array( 'text' => $nextQuest->getText(), 'ans' => array() ); foreach( $ans_arr as $answer ){ $data_arr['ans'][] = array( 'id' => $answer->getID(), 'text' => $answer->getText() ); } header( "content-type: application/json" ); echo json_encode( $data_arr );