Actullay dd()在Laravel中如何工作

时间:2019-04-04 16:42:14

标签: mysql laravel laravel-5.8

我有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 谁能告诉我为什么?

1 个答案:

答案 0 :(得分:1)

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);
}