我正在使用Laravel框架.
我有关于课程创建的问题.为了解释我的问题,我会举个例子:
class articleController extends Controller{
public function bla(){
$a = new MyNewClass($colorfulVariable);
$b = $a->createSomething(new MySecondNewClass());
}
}
Run Code Online (Sandbox Code Playgroud)
现在,这些类MyNewClass和MySecondNewClass不存在的,我想创建它们,在每个控制器我想使用它们,就像我使用重定向或请求类Laravel提供.
我该如何创建这个类?在我的laravel项目中创建一个新函数来使用它们?
我有这个数组:
$variableNames = [
'x1',
'x2',
'x3',
'x4',
'x5',
'x6',
'x7'
];
Run Code Online (Sandbox Code Playgroud)
但是,当我使用这样的array_key_exists函数时:
array_key_exists('x3', $this->variableNames)
Run Code Online (Sandbox Code Playgroud)
它回来了false.但是,如果我有这个数组:
$variableNames = [
'x1' => null,
'x2' => null,
'x3' => null,
'x4' => null,
'x5' => null,
'x6' => null,
'x7' => null
];
Run Code Online (Sandbox Code Playgroud)
它回来了true.我如何使用第一个数组,并得到true?在第一个数组中,值也是null,就像第二个数组一样.那么,为什么第一个数组返回false而第二个数组返回true?
我有这个字符串:
word.word1.word2.word3.word4
Run Code Online (Sandbox Code Playgroud)
我想在第一个之后剪切字符串,.如下所示:
[
1 => 'word',
2 => 'word1.word2.word3.word4'
]
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?explode这还不够.