Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel在关联数组集合上的contains()辅助对象,使用多个参数进行搜索_Php_Laravel_Laravel 5_Collections_Laravel 5.4 - Fatal编程技术网

Php Laravel在关联数组集合上的contains()辅助对象,使用多个参数进行搜索

Php Laravel在关联数组集合上的contains()辅助对象,使用多个参数进行搜索,php,laravel,laravel-5,collections,laravel-5.4,Php,Laravel,Laravel 5,Collections,Laravel 5.4,我收集了这些精确的地理信息系统坐标,我试图通过使用laravel的contains辅助程序传递lat和long来查找位置匹配。以$points形式收集的样本: 我的检查是$points->是否包含$lng,$lat{//do something}。我没有得到任何匹配,所以只是好奇我是否可以在这个上下文中使用contains?我知道它适用于更简单的集合。我试着对从我正在搜索的数据集中提取的完全匹配的数据进行编码,但它仍然返回false。还有一个问题我还没有开始讨论,那就是来自一个设置$lat和$l

我收集了这些精确的地理信息系统坐标,我试图通过使用laravel的contains辅助程序传递lat和long来查找位置匹配。以$points形式收集的样本:

我的检查是$points->是否包含$lng,$lat{//do something}。我没有得到任何匹配,所以只是好奇我是否可以在这个上下文中使用contains?我知道它适用于更简单的集合。我试着对从我正在搜索的数据集中提取的完全匹配的数据进行编码,但它仍然返回false。还有一个问题我还没有开始讨论,那就是来自一个设置$lat和$lng的查询的坐标有6位小数-93.208572,而我正在搜索的GIS数据的坐标有12位小数44.174837264857。我的理解是,contains仍然可以找到匹配项,但我想当我到达那里时,我会穿过那座桥。。。我还尝试使用键/值对拆分检查:

$lngCheck = $points->contains('x', $lng);
$latCheck = $points->contains('y', $lat);

然后检查它们是否都是匹配的。我仍然经常出错。

这可能是Collection的->第一个函数的候选函数,它根据您提供的检查在集合中查找对象。在这种情况下:

$exists = $polygon->points->first(function($point, $index) use ($lat, $lng){
  return $point->x == $lat && $point->y == $lng; 
  // ^ Invert if I've got my coordinates backwards.
});

if($exists){
   // Found a matching point in the collection;
} else {
  // Didn't find a matching point in the collection
}

谢谢那太有用了!
$exists = $polygon->points->first(function($point, $index) use ($lat, $lng){
  return $point->x == $lat && $point->y == $lng; 
  // ^ Invert if I've got my coordinates backwards.
});

if($exists){
   // Found a matching point in the collection;
} else {
  // Didn't find a matching point in the collection
}