当前位置:网站首页>The simplicity of laravel
The simplicity of laravel
2022-07-03 19:41:00 【siner. li】
Use an array to find the required value based on the keys you have
// It is bad
$ceshi = 'epub';
if ($ceshi === 'pdf') {
$type = 'book';
} else if ($ceshi === 'epub') {
$type = 'book';
} else if ($ceshi === 'license') {
$type = 'license';
} else if ($ceshi === 'artwork') {
$type = 'creative';
} else if ($ceshi === 'song') {
$type = 'creative';
} else if ($ceshi === 'physical') {
$type = 'physical';
}
dd($type);
Output : “book”
// The recommended
$ceshi = 'epub';
$type = [
'pdf' => 'book',
'epub' => 'book',
'license' => 'license',
'artwork' => 'creative',
'song' => 'creative',
'physical' => 'physical',
][$ceshi];
dd($type);
Output : “book”
Use short operators
// It is bad
// truthy test
if (! $foo) {
$foo = 'bar';
}
// null test
if (is_null($foo)) {
$foo = 'bar';
}
// isset test
if (! isset($foo)) {
$foo = 'bar';
}
// elegant
// truthy test
$foo = $foo ?: 'bar';
// null test
$foo = $foo ?? 'bar';
// PHP 7.4
$foo ??= 'bar';
// isset test
$foo = $foo ?? 'bar';
// PHP 7.4
$foo ??= 'bar';
边栏推荐
- 2. Template syntax
- QT -- qfile file read / write operation
- 2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
- QT -- qfileinfo file information reading
- The necessity of lean production and management in sheet metal industry
- PR 2021 quick start tutorial, how to create new projects and basic settings of preferences?
- Use of aggregate functions
- Next spread
- Yolov3 network model building
- 7. Data broker presentation
猜你喜欢
Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
第二十章:y= sin(x)/x,漫步坐标系计算,y= sin(x)/x 带廓幅图形,奥运五环,小球滚动与弹跳,流水显示,矩形优化裁剪,r个皇后全控nxn棋盘
第二章:求a,b的最大公约与最小公倍数经典求解,求a,b的最大公约与最小公倍数常规求解,求n个正整数的的最大公约与最小公倍数
2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
Sentinel source code analysis part I sentinel overview
BOC protected alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC supplied by Qiyu
第二章:求长方体数组,指定区间内的完全数,改进指定区间内的完全数
Typora charges, WTF? Still need support
Free hand account sharing in September - [cream Nebula]
Yolov3 network model building
随机推荐
This Chinese numpy quick look-up table is too easy!
2022-06-27 advanced network engineering (XII) IS-IS overhead type, overhead calculation, LSP processing mechanism, route revocation, route penetration
CMD implements the language conversion of locale non Unicode programs
Chapter 1: find the factorial n of n!
FPGA 学习笔记:Vivado 2019.1 工程创建
Utilisation de base du cadre unitest
第一章:求同吗小数和s(d, n)
2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
Bool blind note - score query
Chapter 20: y= sin (x) /x, rambling coordinate system calculation, y= sin (x) /x with profile graphics, Olympic rings, ball rolling and bouncing, water display, rectangular optimization cutting, R que
Rd file name conflict when extending a S4 method of some other package
Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
Day11 - my page, user information acquisition, modification and channel interface
10 smart contract developer tools that miss and lose
Pecan — Overview
第二章:求长方体数组,指定区间内的完全数,改进指定区间内的完全数
Day10 ---- 强制登录, token刷新与jwt禁用
04 -- QT OpenGL two sets of shaders draw two triangles
01. Preparation for automated office (free guidance, only three steps)
Basic principle of LSM tree