strpos()期望参数1是字符串,给定Laravel的数组


strpos() expects parameter 1 to be string, array given Laravel

没错,我正试图使用两个不同的json文件来获取库存中物品的价格。但当谈到CS:GO硬币时,它们没有价格,所以…

这是我的代码:

$json = json_decode(file_get_contents('http://steamcommunity.com/profiles/76561198050605019/inventory/json/730/2'));
$prices  = json_decode(file_get_contents('prices.json'));
$items = [];

foreach($prices->results as $result){
    $items[$result->market_name] = $result;
}
foreach($json->rgDescriptions as $item){
    if (str_contains([' Coin ', ' coin '], $item->market_name)) continue;
    var_dump($item->market_name . ' - $' . $items[$item->market_name]->current_price);
}

这是我获取的错误

public static function contains($haystack, $needles)
{
    foreach ((array) $needles as $needle) {
        if ($needle != '' && strpos($haystack, $needle) !== false) {
            return true;
        }
    }

我宁愿它完全忽略硬币

您的参数设置错误!

if (str_contains($item->market_name, [' Coin ', ' coin '])) continue;