[size=x-large]我的Eloquent单独使用系列文章[/size]
[url=http://xieye.iteye.com/blog/2382907]php的db类库Eloquent单独使用系列(1)[/url]
[url=http://xieye.iteye.com/blog/2383390]php的db类库Eloquent单独使用系列(2) - 分页[/url]
[url=http://xieye.iteye.com/blog/2387809]php的db类库Eloquent单独使用系列(3) - sql日志[/url]
[url=http://xieye.iteye.com/blog/2387983]php的db类库Eloquent单独使用系列(4)- 事件监听[/url]
[url=http://xieye.iteye.com/blog/2383466]php的db类库Eloquent单独使用系列(5)- 模型转数组[/url]
[url=http://xieye.iteye.com/blog/2388023]php的db类库Eloquent单独使用系列(6)- 一对一关联[/url]
[url=http://xieye.iteye.com/blog/2388029]php的db类库Eloquent单独使用系列(7)- 一对多关联[/url]
[url=http://xieye.iteye.com/blog/2388150]php的db类库Eloquent单独使用系列(8)- 多对多关联[/url]
[url=http://xieye.iteye.com/blog/2388162]php的db类库Eloquent单独使用系列(9)- 多对多关联 - 表关联自身[/url]
[url=http://xieye.iteye.com/blog/2388280]php的db类库Eloquent单独使用系列(10)- 多对多关联 - 远程一对多[/url]
[url=http://xieye.iteye.com/blog/2388521]php的db类库Eloquent单独使用系列(11)- 多对多关联 - 添加模型属性[/url]
[url=http://xieye.iteye.com/blog/2389182]php的db类库Eloquent单独使用系列(12)- 结果集模型转数组 - 2[/url]
laravel数据库结果集转成数组的两种方法
这里只贴出部分代码
两次显示的结果是一毛一样的,都是php纯数组。
重要补充:
我写了一个更方便的类,来获得数组,参加
[url]http://xieye.iteye.com/blog/2389182[/url]
[url=http://xieye.iteye.com/blog/2382907]php的db类库Eloquent单独使用系列(1)[/url]
[url=http://xieye.iteye.com/blog/2383390]php的db类库Eloquent单独使用系列(2) - 分页[/url]
[url=http://xieye.iteye.com/blog/2387809]php的db类库Eloquent单独使用系列(3) - sql日志[/url]
[url=http://xieye.iteye.com/blog/2387983]php的db类库Eloquent单独使用系列(4)- 事件监听[/url]
[url=http://xieye.iteye.com/blog/2383466]php的db类库Eloquent单独使用系列(5)- 模型转数组[/url]
[url=http://xieye.iteye.com/blog/2388023]php的db类库Eloquent单独使用系列(6)- 一对一关联[/url]
[url=http://xieye.iteye.com/blog/2388029]php的db类库Eloquent单独使用系列(7)- 一对多关联[/url]
[url=http://xieye.iteye.com/blog/2388150]php的db类库Eloquent单独使用系列(8)- 多对多关联[/url]
[url=http://xieye.iteye.com/blog/2388162]php的db类库Eloquent单独使用系列(9)- 多对多关联 - 表关联自身[/url]
[url=http://xieye.iteye.com/blog/2388280]php的db类库Eloquent单独使用系列(10)- 多对多关联 - 远程一对多[/url]
[url=http://xieye.iteye.com/blog/2388521]php的db类库Eloquent单独使用系列(11)- 多对多关联 - 添加模型属性[/url]
[url=http://xieye.iteye.com/blog/2389182]php的db类库Eloquent单独使用系列(12)- 结果集模型转数组 - 2[/url]
laravel数据库结果集转成数组的两种方法
这里只贴出部分代码
//方法一,代码精简,但实际执行效率低,来回两遍转换,谨慎使用
$result = $conn::table('test_databases')->where('id','<', 3)->get();
var_dump( json_decode( $result->toJson() ,true )) ;
//方法二,利用get_object_vars函数,代码丑陋,但不影响速度。
$result = $conn::table('test_databases')->where('id','<', 3)->get();
$new =[];
foreach ($result->toArray() as $v ) {
$new[]= get_object_vars($v);
}
var_dump($new);
两次显示的结果是一毛一样的,都是php纯数组。
重要补充:
我写了一个更方便的类,来获得数组,参加
[url]http://xieye.iteye.com/blog/2389182[/url]