1
Array ( [0] => { [1] => ★ Bayonet | Blue Steel (Minimal Wear) [2] => :119.41, [3] => ★ StatTrak™ Huntsman Knife | Scorched (Well-Worn) [4] => :101.65 }

I want these items (Comes from the API linked below) to be sorted like this: Example:

ItemName = "★ Bayonet | Blue Steel (Minimal Wear)";
ItemPrice = "119.41";

And that should be repeated for all the items. So we get a name with a price for all items listed.

Right now I have this code:

$priceSource = "https://api.csgofast.com/price/all";
    $priceData = file_get_contents($priceSource);
    $priceList = explode(':',$priceData);
    $priceList = explode(',',$priceData);
    $priceList = explode('"',$priceData);

    print_r($priceList);

1 Answer 1

1

The API in your code returns JSON. After you do $priceData = file_get_contents($priceSource); you can decode it to an array with json_decode.

$decoded = json_decode($priceData, true);

Then you can iterate over the array and do whatever you need to do with the items and their prices:

foreach ($decoded as $item => $price) {
    echo "<p>$item costs $price</p>";       // for example
}
Sign up to request clarification or add additional context in comments.

2 Comments

So what if I have an item in my inventory called ★ Bayonet | Blue Steel (Minimal Wear) and only want to get the price for that specific item. How would I do that?
If you know the exact name of the item, you can get its price by using that name as a key in the decoded array: $price = $decoded['★ Bayonet | Blue Steel (Minimal Wear)'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.