且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel 4-将对象数组转换为单个对象

更新时间:2023-09-07 09:18:34

无论是将三个对象作为单独的变量还是只需要一种访问它们的方法,都不清楚100%的含义.

Its not 100% clear what you mean, whether you want the three objects as seperate variables or you just need a way of accessing them.

一个简单的foreach就足够了.

A simple foreach should suffice.

foreach ( $collection as $model ) 
{
    $id = $model->id;
}

或者,Eugen提供的答案将获取变量的特定索引供您使用.

alternatively the answer supplied by Eugen would grab specific indexes to variables for you to use.