如何搜索多个数组。我正在为数据表制作自定义搜索功能。我怎样才能做到这一点? 我不知道如何在数组中搜索和查找并返回数组。
$records = Array
(
[0] => Array
(
[0] => 28
[1] => http://198.58.98.34:4600/uploads/item/priority_images-1519195620005Item1.png
[2] => Currency
[3] => Demo1
[4] => Hello
[5] => 980
[6] => 2018-02-21T06:47:15.264Z
)
[1] => Array
(
[0] => 27
[1] => http://198.58.98.34:4600/uploads/item/1519120091372-filewinter_is_here_game_of_thrones_hd-1920x1080.jpg
[2] => coins212
[3] => Demo2
[4] => Hello1
[5] => 54564
[6] => 2018-02-21T06:38:04.053Z
)
);
$search = $request['search']['value'];
我尝试使用 array_column
但它不起作用。
如何搜索并返回搜索到的数据?
最佳答案
你可以在 laravel 中使用 collect
函数来制作 collection以及使用where函数进行过滤
$collect = collect($records);
$search = $collect->where('search_column','value');
在您的示例中,您可以使用列号作为。即第 3 列,键是 2
$search = $collect->where('2','Currency');
将在第三列即给出具有Currency
的数组。使用 key 2
请检查所有可用的收集方法here
关于php - 在 Laravel 中对多维数组应用搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48900214/