actullay dd() 如何在 laravel 中工作

How does actullay dd() works in laravel

我有 sql 命令,例如

$kos = DB::select('SELECT team,round,SUM(points) AS total from points WHERE round="first" GROUP by team ORDER BY total desc, run_rate desc limit 4');

当我 dd($kos) 它会给我这个输出 see here 但是当我 运行 这个

$kos = DB::select('SELECT team,round,SUM(points) AS total from points WHERE round="first" GROUP by team ORDER BY total desc, run_rate desc limit 4');
foreach($kos as $ko){
        dd($ko->team);
}

它会给我这个输出 see here 谁能告诉我为什么?

dd 将转储传递的值并退出脚本的执行

在第一种情况下,您将集合传递给 dd ,它将转储整个集合并停止执行脚本

在第二种情况下,您处于第一个循环中并转储团队价值并停止执行

如果你只想转储值而不停止执行,你应该调用 dump 函数而不是

试试这个

DB::select('SELECT team,round,SUM(points) AS total from points WHERE round="first" GROUP by team ORDER BY total desc, run_rate desc limit 4');
foreach($kos as $ko){
        dump($ko->team);
}