当前位置:网站首页>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';
边栏推荐
- Kubernetes cluster builds efk log collection platform
- Chapter 1: simplify the same code decimal sum s (D, n)
- February 14-20, 2022 (osgear source code debugging +ue4 video +ogremain source code transcription)
- 2022-06-30 網工進階(十四)路由策略-匹配工具【ACL、IP-Prefix List】、策略工具【Filter-Policy】
- Use of aggregate functions
- Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
- 第一章:求n的阶乘n!
- Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
- Today I am filled with emotion
- 第一章:三位阶乘和数,图形点扫描
猜你喜欢

Think of new ways

BOC protected tryptophan porphyrin compound (TAPP Trp BOC) Pink Solid 162.8mg supply - Qiyue supply

第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组

第一章: 舍罕王失算

Summary of composition materials for 2020 high-frequency examination center of educational resources

PR FAQ: how to set PR vertical screen sequence?

Merge K ascending linked lists

Typora charges, WTF? Still need support

PR 2021 quick start tutorial, how to create new projects and basic settings of preferences?

Octopus online ecological chain tour Atocha protocol received near grant worth $50000
随机推荐
Kubernetes cluster builds efk log collection platform
What is the content of game modeling
6. Data agent object Defineproperty method
第一章:递归求n的阶乘n!
2022 Xinjiang latest road transportation safety officer simulation examination questions and answers
2022-07-02 advanced network engineering (XV) routing policy - route policy feature, policy based routing, MQC (modular QoS command line)
Chapter 1: extend the same code decimal sum s (D, n)
CesiumJS 2022^ 源码解读[7] - 3DTiles 的请求、加载处理流程解析
01. Preparation for automated office (free guidance, only three steps)
2022-06-27 advanced network engineering (XII) IS-IS overhead type, overhead calculation, LSP processing mechanism, route revocation, route penetration
PR 2021 quick start tutorial, how to create new projects and basic settings of preferences?
Flume learning notes
How to build an efficient information warehouse
Typora charges, WTF? Still need support
第一章: 舍罕王失算
2. Template syntax
Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
OSPF - detailed explanation of stub area and full stub area
Luogu-p1107 [bjwc2008] Lei Tao's kitten
第一章:三位阶乘和数,图形点扫描