从索引中获取值并在 Laravel/Php 中内爆该值
当我使用 dd() 推荐时我的控制器代码
$StudentData = StudentModel::getStudentList();
//dd($StudentData);
foreach ($StudentData as $data)
{
print_r(array($data->Student_name));
}
并且我得到索引值,就像
Illuminate\Database\Eloquent\Collection {#588 ▼
#items: array:2 [▼
0 => App\Models\Student {#585 ▼
#attributes: array:4 [▶]
#original: array:4 [▼
"StudentId" => 2
"Student_register_number" => 11
"Student_name" => "Tom"
"Student_make_percentage" => "69.00"
]
#guarded: array:1 [▶]
}
1 => App\Models\Student {#575 ▼
#attributes: array:4 [▶]
#original: array:4 [▼
"StudentId" => 2
"Student_register_number" => 11
"Student_name" => "John"
"Student_make_percentage" => "65.00"
]
我使用 print_r(array($data->Student_name)); 时 一样并运行输出 我得到这样的
Array
(
[0] => Tom
)
Array
(
[0] =>John
)
结果,我真正想要的是
array (2)=>
[
'0'=>Tom,
'1'=>'john',
]
如何从索引中单独获取所有 Student_name 。并将其存储为上面的索引值
My Controller Code
$StudentData = StudentModel::getStudentList();
//dd($StudentData);
foreach ($StudentData as $data)
{
print_r(array($data->Student_name));
}
when i Use dd() commend and I get index values like
Illuminate\Database\Eloquent\Collection {#588 ▼
#items: array:2 [▼
0 => App\Models\Student {#585 ▼
#attributes: array:4 [▶]
#original: array:4 [▼
"StudentId" => 2
"Student_register_number" => 11
"Student_name" => "Tom"
"Student_make_percentage" => "69.00"
]
#guarded: array:1 [▶]
}
1 => App\Models\Student {#575 ▼
#attributes: array:4 [▶]
#original: array:4 [▼
"StudentId" => 2
"Student_register_number" => 11
"Student_name" => "John"
"Student_make_percentage" => "65.00"
]
when i Use print_r(array($data->Student_name)); and run the out put
i get Like This
Array
(
[0] => Tom
)
Array
(
[0] =>John
)
what actually result i want is
array (2)=>
[
'0'=>Tom,
'1'=>'john',
]
how i want to get All Student_name alone from index .and store that as index value as above
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个...
Try this...