Route::get('/my_home/helper', function(){
$arr = [
'name'=>'lisi',
'age' =>18,
'job' =>'worker'
];
return array_except($arr,'job'); 结果:{"name":"lisi","age":18}
});
6>array_flatten():返回最终值:
Route::get('/my_home/helper', function(){
$arr = [
'a'=>1,
'b' =>[
'a'=>2,
'b'=>3
]
];
return array_flatten($arr); 结果:[1,2,3]
});
7>array_where():
Route::get('/my_home/helper', function(){
$arr = [
'name'=>'lisi',
'age'=>18,
'job'=>'worker'
];
return array_where($arr,function($k, $v){
return is_string($v); 结果:{"name":"lisi","job":"worker"}
});
});
8>last():返回最后一个值:
Route::get('/my_home/helper', function(){
$arr = [
1,2,3
];
return head($arr); 结果:返回3
});
第二、路径(path)帮助函数
1>app_path():返回项目中的绝对路径
Route::get('/my_home/helper', function(){
return app_path(); 结果:E:\web\htdocs\lar\app
});
2>config_path():返回的是config的路径
Route::get('/my_home/helper', function(){
return config_path(); 结果:E:\web\htdocs\lar\config
});
3>public_path():返回的是public路径
Route::get('/my_home/helper', function(){
return public_path(); 结果:E:\web\htdocs\lar\public
});
4>storage_path():返回storage路径
Route::get('/my_home/helper', function(){
return storage_path(); 结果:E:\web\htdocs\lar\storage
});
第三、字符串(string)帮助函数
1>str_plural()将单数变为复数,如:sheep它是单复数同行就不会改变的
Route::get('/my_home/helper', function(){
return str_plural("apple"); 结果:apples
});
2>starts_with():判断字符串是否已某一个开始的,返回布尔值
Route::get('/my_home/helper', function(){
dd(starts_with("apple", 'a'));
});
3>starts_with():判断字符串是否已某一个结束的,返回布尔值
4>camel_case():转换成驼峰命名
"helloWorld"
Route::get('/my_home/helper', function(){ dd(camel_case("hello_world"));
结果:helloWorld});
5>class_basename():
Route::get('/my_home/helper', function(){
dd(class_basename("App\Http\Controllers\Controller")); 结果:Controller
});
6>str_limil():限制字符串长度
Route::get('/my_home/helper', function(){
dd(str_limit("abcd",3)); 结果:abc...
});
7>str_is():判断某个字符串是否满足某一个规则,返回布尔值,第一个参数的条件
Route::get('/my_home/helper', function(){
dd(str_is('ab*','abcd'));
});