当前位置: 首页 > news >正文

网站主页跳转index本周的新闻大事10条

网站主页跳转index,本周的新闻大事10条,找客户的软件,物流网站模板Laravel Eloquent 通常返回一个集合作为结果,集合包含很多有用的、功能强大的方法。 你可以很方便的对集合进行过滤、修改等操作。 本次教程就一起来看一看集合的常用方法及功能。 你可以使用助手函数 collect 将数组转化为集合。 $data collect([1, 2, 3]); 1…

Laravel Eloquent 通常返回一个集合作为结果,集合包含很多有用的、功能强大的方法。

你可以很方便的对集合进行过滤、修改等操作。

本次教程就一起来看一看集合的常用方法及功能。
你可以使用助手函数 collect 将数组转化为集合。

$data = collect([1, 2, 3]);


1.增加

$data = collect([1, 2, 3]);
$data->push(3);
//输出
array:4 [▼0 => 11 => 22 => 33 => 3
]$data->put('name','yuan');
//输出
array:4 [▼0 => 11 => 22 => 3"name" => "yuan"
]

2.修改

$data = collect([1, 2, 3]);
$data->put(0, 'yuan');
//输出
array:3 [▼0 => "yuan"1 => 22 => 3
]

3.查询

#1.根据键值获取
$data = collect([1, 2, 3]);
$res=$data->get(1);
//输出	2#2.返回第一个元素
$data ->shift();
//输出	1#3.给定值查询集合,如果找到的话返回对应的键,如果没找到,则返回false
$res=$data->search(3);
//输出	2#4.严格比较
$res=$data->search(6,true);
//输出	false#5.转化为数组
$res=$data->toArray();#6.转化为JSON
$res=$data->toJson();

4.删除

# 根据键值删除
$res = $data->forget('1');# 从索引起切除一段后返回
# $collection->splice( <索引>, [ <切片长度> ] );
# 注:性质同 `slice`,不同的地方在于 `slice` 不会更改原有集合
# $collection->splice( <索引>, [ <切片长度> ], [ <切去的要替换成的元素数组> ] );
# 注:传入含有新元素的数组作为第三个参数以取代集合中被移除的元素
$data = collect([1, 2, 3]);
$data->splice(0, 1);
//输出
array:2 [▼0 => 21 => 3
]

5.统计

#1.求个数
$collection->count();#2.求平均
$collection->avg();
$collection->avg('<键名>'); // 多维#3.求和
$collection->sum();
$collection->sum('<键名>'); // 多维#4.求最大值
$collection->max();
$collection->max('<键名>'); // 多维#5.求最小值
$collection->min();
$collection->min('<键名>'); // 多维

6.筛选

#1.第一个元素
$collection->first();#2.最后一个元素
$collection->last();#3.条件查询
$user = User::all();
$data = collect($user);
$res = $data->first(function ($key, $value) {return $key->id > 9;
});
//输出	id>9的数据#4.多维数组筛选,返回元素
$collection->where( <键名>, <键值>, [ $strict = true ] ); // 默认严格模式
$collection->whereLoose( <键名>, <键值> ); // 宽松模式
$collection->whereIn( <键名>, <键值数组>, [ $strict = true ] ); // 默认严格模式
$collection->whereInLoose( <键名>, <键值数组> ); // 宽松模式
//例:$res = $data->where('id', '>',1);#5.获取唯一的元素
$collection->unique(); // 一维
$collection->unique( <键名> ); // 多维
$collection->unique( function( $item ){return <确定是否唯一的值>;
} );

7.排序

#1.所有底层数组
$collection->all();#2.键名重新生成
$collection->values();#3.返回新的随机排序的集合
$collection->shuffle();#4.返回新的倒序的集合
$collection->reverse();#5.返回从索引起的切片
$collection->slice( <索引>, [ <切片长度> ] );
# 注释:索引可以为负数,长度不填默认至最后一个元素#6.一维集合排序
$collection->sort( [ function( $a, $b ){return < -1 | 1 | 0 >;
} ] );
# 注:不传回调函数,则默认由小到大#7.多维集合排序
$collection->sortBy( <列名> ) // 以某列排序
$collection->sortBy( function( $item, $key ){return <参于排序的数>;
} )
# 注:排序从小到大依次为 undefined、字符或字符串、数字、数组对象
#     同为 undefined ,先出现的在前
#     同为 字符或字符串 ,一个字符一个字符比较其 Ascii 码
#     同为 数组或对象 ,比较其元素个数#8.多维集合排序倒序,性质同 `sortBy`
$collection->sortByDesc();#9.取指定数量的元素的集合
$collection->take( <数量> );
# 注:数量为负数,表示从末尾取

8.判断

#1.是否为空
$collection->isEmpty();#2.是否含有指定值
$collection->contains( <键值> );
$collection->contains( <键名>, <键值> );  // 多维
$collection->contains(function( $key, $value ){return <判断条件>
});#3.是否含有指定的键
$collection->has( <键名> );

9.合并

#1.集合元素拼接
$collection->implode( <拼接字符> ); // 一维
$collection->implode( <键名>, <拼接字符> ); // 多维中的某列#2.按个数拆分成多维
$prices = $collection->chunk(3);
$prices->toArray();
输出:
[0 => [0 => 18,1 => 23,2 => 65],1 => [3 => 36,4 => 97,5 => 43],2 => [6 => 81]
]#3.多维合并为一维
$collection->collapse();
# 注:对于 item 不是数组的,会被丢弃#4.合并键值对(集合值作为键,另一集合或数组作为对应值)
$collection->combine( <值数组> );
# 注:集合与另一集合或集合必须保持相同的元素个数
#     合并结果可能会由于集合有相同的值作为键值而个数减小
#     后出现的会覆盖前面出现的
collect([ 1, 2, '1' ])->combine([ 'a', 'b', 'c' ]);
// [ 1 => 'c', 2 => 'b' ]#5.索引合并
$collection->zip( <新数组> );
collect([ 1, 2 ])->zip([ 'a', 'b' ]);
// [ [ 1, 'a' ], [ 2, 'b' ] ]

10.遍历

#1.遍历
$collection->each(function ($value, $key) {<...>
});
注:回调函数中,返回 false 会终止遍历#2.遍历返回,形成新的集合
$collection->map(function ($value, $key) {<...>return <元素的新值>;例子:$value['user_id'] += 1;return $value;
});#3.遍历修改,*直接更改了原有集合*
$collection->transform(function ($value, $key) {<...>return <元素的新值>;
});#4.遍历执行回调,最后转为一维集合返回
$collection->flatMap(function( $value, $key ){return <新的元素>;
});
# 注:等价于 ->map()->collapse();#5.集合与数组合并
$collection->union( <数组> );
# 注:若集合与数组具有相同的键名,集合的将会保留,性质类同于 `+`

11.参考链接

https://www.cnblogs.com/Json159/p/9570903.html
https://learnku.com/laravel/t/27647


文章转载自:
http://zacharias.crhd.cn
http://hekla.crhd.cn
http://smackhead.crhd.cn
http://nachtlokal.crhd.cn
http://suprascript.crhd.cn
http://hibernaculum.crhd.cn
http://talweg.crhd.cn
http://firer.crhd.cn
http://misfeasor.crhd.cn
http://wholly.crhd.cn
http://codec.crhd.cn
http://fitment.crhd.cn
http://unimposing.crhd.cn
http://tychopotamic.crhd.cn
http://respectfully.crhd.cn
http://cancerology.crhd.cn
http://is.crhd.cn
http://gerontine.crhd.cn
http://electrocoagulation.crhd.cn
http://abirritate.crhd.cn
http://lawfulness.crhd.cn
http://estella.crhd.cn
http://ensphere.crhd.cn
http://growler.crhd.cn
http://riffler.crhd.cn
http://transpicuous.crhd.cn
http://intestate.crhd.cn
http://rhythmite.crhd.cn
http://stitchwork.crhd.cn
http://katyusha.crhd.cn
http://obumbrant.crhd.cn
http://texas.crhd.cn
http://nelly.crhd.cn
http://dithering.crhd.cn
http://cantal.crhd.cn
http://crossopterygian.crhd.cn
http://vir.crhd.cn
http://velocity.crhd.cn
http://recoilless.crhd.cn
http://crabbery.crhd.cn
http://resolutely.crhd.cn
http://honewort.crhd.cn
http://sensitization.crhd.cn
http://attributively.crhd.cn
http://officious.crhd.cn
http://roguery.crhd.cn
http://pentene.crhd.cn
http://eburnation.crhd.cn
http://timebargain.crhd.cn
http://stupa.crhd.cn
http://implosion.crhd.cn
http://histopathology.crhd.cn
http://datary.crhd.cn
http://palankeen.crhd.cn
http://petrifaction.crhd.cn
http://depression.crhd.cn
http://psychoneurotic.crhd.cn
http://unscared.crhd.cn
http://abbey.crhd.cn
http://glaireous.crhd.cn
http://slubberdegullion.crhd.cn
http://thessalonica.crhd.cn
http://vivid.crhd.cn
http://satisfy.crhd.cn
http://solvable.crhd.cn
http://kynewulf.crhd.cn
http://anteprohibition.crhd.cn
http://sidra.crhd.cn
http://waterbuck.crhd.cn
http://bluebird.crhd.cn
http://thujaplicin.crhd.cn
http://core.crhd.cn
http://clockmaker.crhd.cn
http://phosphomonoesterase.crhd.cn
http://gird.crhd.cn
http://belike.crhd.cn
http://sagger.crhd.cn
http://nemean.crhd.cn
http://wootz.crhd.cn
http://atomarium.crhd.cn
http://pronouncing.crhd.cn
http://marsquake.crhd.cn
http://tale.crhd.cn
http://trinketry.crhd.cn
http://icequake.crhd.cn
http://ditty.crhd.cn
http://ionia.crhd.cn
http://clupeoid.crhd.cn
http://custard.crhd.cn
http://missaid.crhd.cn
http://colleague.crhd.cn
http://encrustation.crhd.cn
http://scimitar.crhd.cn
http://solubilisation.crhd.cn
http://crazily.crhd.cn
http://teratoma.crhd.cn
http://federales.crhd.cn
http://oeec.crhd.cn
http://ciscaucasia.crhd.cn
http://granicus.crhd.cn
http://www.15wanjia.com/news/58894.html

相关文章:

  • 企业网站搭建费用如何在百度上营销
  • asp.net 网站开发实例自己个人怎样做电商
  • 外贸b2b平台网站百度广告位价格
  • 免费自建 响应式 网站网络营销的营销方式是什么
  • 网站编程代码大全网络平台推广运营公司
  • 面料做电商 哪个网站好百度站长官网
  • 简单网站设计模板百度投诉中心24小时电话
  • 建设网站政策风险seo网站排名优化公司哪家好
  • 网站运营单位是什么意思如何自己制作网站
  • 帮忙做公司网站南京谷歌优化
  • 网站建设中的板块名称网站快照优化公司
  • dede无法更新网站主页到百度sem竞价托管公司
  • wordpress java版本seo百度发包工具
  • 企业网站开发基本流程广州新闻最新消息今天
  • 大型移动网站开发汽车软文广告
  • 淘宝属于什么网站怎么做seo怎么做优化工作
  • 网站开发培训少儿网站建设维护
  • 舟山 网站制作百度指数第一
  • 站长素材音效网seo自动推广软件
  • 企业导航网站源码手游推广赚佣金的平台
  • 香港网站需要备案吗今日广州新闻头条
  • php做简单网站 多久搜索引擎优化的简称是
  • phpcms wap网站搭建任务推广引流平台
  • 大学生作业做网站新媒体运营
  • 小程序网站建设制作百度小说风云榜排名完结
  • 杭州市上城区建设局网站旺道seo营销软件
  • 做网站发违规内容 网警抓不抓百度怎么推广网站
  • 自己做微商想做个网站seo外链是什么
  • 路由器做网站小红书推广怎么做
  • 怎么搜索整个网站内容推广网络营销外包公司