【问题标题】:strpos() expects parameter 1 to be string, array given Laravelstrpos() 期望参数 1 是字符串,给定 Laravel 的数组
【发布时间】:2015-11-22 00:56:23
【问题描述】:

是的,我正在尝试使用两个不同的 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;
        }
    }

我希望它完全忽略硬币

【问题讨论】:

    标签: php laravel laravel-5.1 steam steam-web-api


    【解决方案1】:

    你的参数弄错了!

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

    【讨论】:

      猜你喜欢
      • 2018-07-04
      • 1970-01-01
      • 2018-02-22
      • 2018-11-10
      • 2017-08-08
      • 2017-09-23
      • 1970-01-01
      • 2019-09-19
      • 2016-10-26
      相关资源
      最近更新 更多