php - 在 Laravel 中对多维数组应用搜索

标签 php laravel

如何搜索多个数组。我正在为数据表制作自定义搜索功能。我怎样才能做到这一点? 我不知道如何在数组中搜索和查找并返回数组。

$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/

相关文章:

php - 更改要从数据库中获取的列的名称

php - 在单元测试中动态设置 Yii Controller

php - 如何授予 heroku 上特定文件夹的权限?

php - Laravel 4 查询生成器(连接)

laravel - Selenium 和 Laravel 5.2

php - laravel 中的存储库模式相对于在 Controller 构造函数中实例化模型的优势

git - pull pull 维尔 5 : Remove development dependancies from app config file

php - 显示数据库中的数据

php - 警告 : mail() expects parameter 4 to be string

php - 使用 mySQL 每天获取新的表数据