strpos() 期望参数 1 是字符串,数组给定 Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33850456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
strpos() expects parameter 1 to be string, array given Laravel
提问by Skel
Right Im trying to get the prices for items in my inventory using two different json files. But when it comes to the CS:GO coins they have no price so...
对,我正在尝试使用两个不同的 json 文件获取库存中物品的价格。但是当谈到 CS:GO 硬币时,它们没有价格,所以......
Here is my code:
这是我的代码:
$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);
}
And here is the error im getting
这是我得到的错误
public static function contains($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ($needle != '' && strpos($haystack, $needle) !== false) {
return true;
}
}
I would prefer it to just ignore the coins altogether
我宁愿它完全忽略硬币
采纳答案by Jordan Doyle
You got your parameters the wrong way round!
你把参数弄错了!
if (str_contains($item->market_name, [' Coin ', ' coin '])) continue;