gpt4 book ai didi

php - 如何显示可读数组 - Laravel

转载 作者:IT王子 更新时间:2023-10-29 00:19:29 25 4
gpt4 key购买 nike

在我写完之后:

Route::get('/', function()
{
dd(User::all());
});

刷新浏览器后,我得到一个不可读的数组。有没有办法以可读格式获取该数组?

最佳答案

dd()转储变量并结束脚本 (1) 的执行,因此用 <pre> 包围它标签会使它损坏。只需使用好的 ol' var_dump() (或者 print_r() 如果你知道它是一个数组)

Route::get('/', function()
{
echo '<pre>';
var_dump(User::all());
echo '</pre>';
//exit; <--if you want
});

更新:

我认为您可以通过让 Laravel 将模型对象转换为数组来格式化显示的内容:

Route::get('/', function()
{
echo '<pre>';
$user = User::where('person_id', '=', 1);
var_dump($user->toArray()); // <---- or toJson()
echo '</pre>';
//exit; <--if you want
});

(1) 作为记录,这是 dd() 的实现:

function dd()
{
array_map(function($x) { var_dump($x); }, func_get_args()); die;
}

关于php - 如何显示可读数组 - Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20771239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com