I find myself constantly writing if statements like the following:
if(isset($this->request->data['Parent']['child'])){
$new_var['child'] = $this->request->data['Parent']['child'];
}
My question is, without creating a new shorter variable before the if
statement, is there a magic php process that will help avoid having to rewrite $this->request->data['Parent']['child']
in the body of the if statement? I also want to keep the code clean for any successor developers.
I am also not looking for a ternary solution.
Something a little more along the lines of jquery's use of this
. (That I know of) php doesn't allow anonymous functions or it's not common practice and I'm not saying I want a bunch of anonymous functions all over my classes either.
UPDATE Added in php 7 What does double question mark (??) operator mean in PHP