Laravel 的 dd() 仅显示 foreach() 中的第一次迭代

问题描述 投票:0回答:1

我有像这样的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

谁能告诉我为什么?

php laravel laravel-5.8 dump dd
1个回答
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);
} 
© www.soinside.com 2019 - 2024. All rights reserved.