@UncleDenn

Как вывести цены с парсера?

Всем привет,у меня такой вопрос:
код парсера вещей:
public function loadMyInventory() {
        if(Auth::guest()) return ['success' => false];
		$prices = json_decode(File::get('prices.txt'), true);
		
		if (Session::get('applocale') == 'ru') {
        	$response = json_decode(file_get_contents('https://steamcommunity.com/inventory/'.$this->user->steamid64.'/730/2?l=russian&count=5000'), true);
		} else {
			$response = json_decode(file_get_contents('https://steamcommunity.com/inventory/'.$this->user->steamid64.'/730/2?l=english&count=5000'), true);
		}
		if(time() < (Session::get('InvUPD') + 5)) {
			return [
				'success' => false,
				'msg' => 'Произошла ошибка. Повторите через '.(Session::get('InvUPD') - time() + 5).' сек.',
				'status' => 'error'
			];
		}
        //return $response;
        $inventory = [];
        
        foreach($response['assets'] as $item) {
            $find = 0;
            foreach($response['descriptions'] as $descriptions) {
                if($find == 0) {
                    if(($descriptions['classid'] == $item['classid']) && ($descriptions['instanceid'] == $item['instanceid'])) {
                        $find++;
                        # Если мы нашли цену на итем, то идем дальше.
                        if(isset($prices['data']['prices'][0]['market_hash_name'])) {
                            # Поиск данных
                            $price = $prices['data']['prices'][0]['price']*$this->config->curs;
                            $class = false;
                            $text = false;
                            
                            if($price <= $this->config->min_dep_sum) {
                                $price = 0;
                                if (Session::get('applocale') == 'ru') {
                                    $text = 'Дешевое';
                                } else {
                                    $text = 'Cheap';
                                }
                                $class = 'minPrice';
                            }
                            
                            if(($descriptions['tradable'] == 0) || ($descriptions['marketable'] == 0)) {
                                $price = 0;
                                $class = 'minPrice';
                                if (Session::get('applocale') == 'ru') {
                                    $text = 'Нельзя передавать';
                                } else {
                                    $text = 'Not tradable';
                                }
                            }
                            # Добавление в массив
                            $inventory[] = [
                                'name' => $descriptions['market_name'],
                                'price' => floor($price),
                                'color' => $this->getRarity($descriptions['tags']),
                                'tradable' => $descriptions['tradable'],
                                'class' => $class,
                                'text' => $text,
                                'classid' => $item['classid'],
                                'assetid' => $item['assetid'],
                                'instanceid' => $item['instanceid']
                            ];   
                        }
                    }
                }
            }
        }
        Session::put('InvUPD', (time() + 5));
        return [
            'success' => true,
            'items' => $inventory
        ];
    }

как вывести цену(price)в такой структуре:
{
"status" : "success",
"prices" : [
{
"appid" : "730",
"market_hash_name" : "AK-47 | Aquamarine Revenge (Battle-Scarred)",
"price" : "13.27",
"pricing_mode" : "market",
"skewness" : "-0.19",
"created_at" : 1501407594,
"icon_url" : "https://steamcommunity-a.akamaihd.net/economy/imag...",
"name_color" : "D2D2D2",
"quality_color" : "EB4B4B"
},
  • Вопрос задан
  • 193 просмотра
Пригласить эксперта
Ответы на вопрос 2
dimonchik2013
@dimonchik2013
non progredi est regredi
Комментировать
@asmodeusta
PHP Developer (Laravel, Wordpress)
Используйте json_encode для полученного массива.
function renderArr($your_array) {
    echo json_encode($your_array);
}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы