我查看了官方文档,但我似乎仍然无法访问自变量,例如“城市”。在 sql 查询之后,我使用 $results[0] 来获取它。我如何访问“城市”?
$results = DB::table('users')->get();
birthdate = "0000-00-00 00:00:00";
city = "Laguna Hills";
country = "<null>";
"created_at" = "2014-07-21 07:11:06";
email = "sammy0@gmail.com";
id = 1;
"is_verified" = "<null>";
"location_lat" = "<null>";
"location_lon" = "<null>";
password = RightNow25;
"updated_at" = "0000-00-00 00:00:00";
username = sammy0;
zip = "<null>";
最佳答案
尝试使用“print_r”将完整输出打印到页面(请参阅下面的代码)。它非常有用,因为您可以查看数组中的所有元素及其键和值。
//(using print_r between '<pre>' and '</pre>' formats the data to a human readable format)
print '<pre>';
print_r($results);
print '</pre>';
这应该有助于确定您的数据是否按预期返回。
关于php - 从mysql查询结果数组访问信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24864622/