Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

emilpapelas4@gmail.com's avatar

Trying to get the data from array but dont works.

i have the following api (https://steamcommunity.com/inventory/76561198087029659/730/2) the have the key of 'description' to get the items.

$steamID= 76561198087029659;
      $inventoryJsonUrl = 'http://steamcommunity.com/inventory/'.$steamID.'/730/2';
      $inventoryJsonGet = file_get_contents($inventoryJsonUrl);
      $inv = json_decode($inventoryJsonGet, TRUE);
      
      dd($inv['descriptions']);

This code give me the following values https://imgur.com/XEU93Dj

Issues it that 'descriptions key ' contain again an list of array and i need to get that data someting like

$item['name'],
$item['icon_url'],
$item['name_color'],
etc

Please help me . Thanks

0 likes
17 replies
lbecket's avatar

Can't you reference the data by the array's index? So $inv['descriptions'][0] for example.

Perhaps you need to iterate over the array being returned?

1 like
MohamedTammam's avatar
Level 51

What's wrong with foreach?

foreach($inv['descriptions'] as $item) {
$item['name'];
$item['icon_url'];
$item['name_color'];
// ...
}
1 like
MohamedTammam's avatar

@emilpapelas4@gmail.com You need to loop over tags array to find the color.

foreach($inv['descriptions'] as $item) {
$item['name'];
$item['icon_url'];
$item['name_color'];
	foreach($item['tags'] as $tag) {
		if(isset($tag['color']) {
			// Do your logic.
		}
	}
// ...
}
emilpapelas4@gmail.com's avatar

@MohamedTammam https://imgur.com/0rZnm9f

foreach($inv['descriptions'] as $item) 
     {
      $items=Items::Create([
        'name' => $item['market_name'],
        'icon_url' => $item['icon_url'],
        'tradable' => $item['tradable'],

        foreach($item['tags'] as $tag) 
        {
            if(isset($tag['color']) {
              'color' => $tag['color'],
            }
        }
        
    ]);
     }

Please or to participate in this conversation.