Q:

How can I write better code for this condition?

I want to avoid using to nested if statements
if (! is_null($user)){
    if($user->id == $currentUser->id){
       echo 'its for me';
    }else{
        echo 'its not for me';
    }
}else{
    echo 'its not for me';
}

And please note I do not want to use return statements

A:

You could try something like this:
isset function and === operator makes it better.
 if (isset($user) && $user->id === $currentUser->id) {

    echo 'its for me';

 } else {

    echo 'its not for me';
 }

Hope this helps.
Peace! xD

