if (count($error) > 0) { //Если ошибки есть, выведем их в формате JSON и остановим работу сценария $error = array('status' => 'error', 'message' => implode(',', $error)); exit(json_encode($error)); } else { return true; } } public function index() { //Перед отправкой SOAP запроса проверим данные отправленные пользователем //Если имеются ошибки, сценарий остановится и отобразит их в формате JSON $this->checkError(); $array = array('from' => $this->str($_POST['from']), 'to' => $this->str($_POST['to']), 'day' => $this->str($_POST['day']), 'month' => $this->str($_POST['month'])); //Отправим запрос на создание SOAP клиента и посылки $result = $this->soap($this->str($_POST['train']), $array); $count = count($result->route_list->stop_list) - 1; $stop_list = array(); for ($i = 0; $i <= $count; $i++) { //Формируем массив следования поезда (остановки) $stop_list[] = array('stop' => $result->route_list->stop_list[$i]->stop, 'arrival_time' => $result->route_list->stop_list[$i]->arrival_time, 'departure_time' => $result->route_list->stop_list[$i]->departure_time, 'stop_time' => $result->route_list->stop_list[$i]->stop_time); } $json = array('status' => 'success', 'number' => $result->train_description->number, 'from' => $result->train_description->from, 'to' => $result->train_description->to, 'stop_list' => $stop_list); //Остановки //Возвращаем результат в формате JSON return json_encode($json); } } $Engine = new Engine(); echo $Engine->index();