比较 laravel 中集合的两列?

Compare two columns of a collection in laravel?

我想比较一个的两列 collection.I 不想在数据库级别执行此操作,只能在集合级别执行此操作。

我有一个这样的集合(为了便于阅读,我在数组模型中返回了它)

   array:3 [
  0 => array:5 [
    "total_amount" => 200000.0

    "admin_max_amount" => "200000000"


  ]
  1 => array:5 [
    "total_amount" => 100000.0

    "admin_max_amount" => "200000000"


  ]
  2 => array:5 [
    "total_amount" => 100000.0

    "admin_max_amount" => "0"

  ]
]

我想先得到其中 total_amount > admin_max_amount.

这里有一个更'Laravel'的方法:

$items = collect([
    [
        "total_amount" => 200000.0,

        "admin_max_amount" => "200000000",
    ],
    [
        "total_amount"     => 100000.0,
        "admin_max_amount" => "200000000",
    ],
    [
        "total_amount"     => 100000.0,
        "admin_max_amount" => "0",
    ],
]);
$result = $items->first(function ($item)
{
    return (float)$item['total_amount'] > (float)$item['admin_max_amount'];
});
dump($result);