代码:
<?php
$url = "http://steamcommunity.com/id/SmokeySYT/inventory/json/730/2";
$json = json_decode(file_get_contents($url));
?><div class="deposit_box"><?php
foreach($json->rgDescriptions as $value => $v) {
if ($v->tradable === 1) {
$url2 = "http://steamcommunity.com/market/priceoverview/?appid=730&market_hash_name=" . $v->market_hash_name;
$url2 = str_replace(" ", "%20", $url2);
$json2 = json_decode(file_get_contents($url2), true);
if ($json2["success"] == true OR !empty($json)) {
$json2["median_price"] = str_replace("$", "", $json2["median_price"]);
$number = floatval($json2["median_price"]);
if ($number > 0.30) {
echo "it worked.";
} else {
echo "it didn't work.";
}
} else {
die("rip");
}
$name = $v->market_hash_name;
$icon_url = $v->icon_url;
?>
<div class="img__wrap">
<img class="img__img" src="http://cdn.steamcommunity.com/economy/image/<?=$icon_url?>" />
<div class="img__description_layer">
<p class="img__description"><?= $name ?></p>
</div>
</div>
<?php
} else {
}
}
?>
</div>
在这里你可以看到它有效:
http://phpfiddle.org/main/code/z7dd-2c0h
所以有变量$ json2 [“median_price”]这是一个字符串,我试着用很多不同的方式把它放在if语句中,但我不能让它工作所以我的if语句检查是否值在字符串中大于0.30,尽管我尝试用很多不同的方式使用intval()。
($ json2 [“median_price”]的值对于每个图像都不同,并且有一个图像的值为0.39,但它仍然说“它不起作用”。)